diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 376dfb957554..48c7e82a9677 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -144,7 +144,7 @@ jobs: name: "${{ github.sha }}-e2e-coverage" path: ./tests/e2e-profile.out - test-system: + test-system: # v2 system tests are in v2-test.yml runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -183,16 +183,6 @@ jobs: name: "testnet-setup" path: ./systemtests/testnet/ retention-days: 3 - - name: system tests v2 - if: env.GIT_DIFF - run: | - COSMOS_BUILD_OPTIONS=v2 make test-system - - uses: actions/upload-artifact@v3 - if: failure() - with: - name: "testnet-setup" - path: ./systemtests/testnet/ - retention-days: 3 repo-analysis: runs-on: ubuntu-latest diff --git a/.github/workflows/v2-test.yml b/.github/workflows/v2-test.yml index 6896f803a2c1..e26e12c0f402 100644 --- a/.github/workflows/v2-test.yml +++ b/.github/workflows/v2-test.yml @@ -109,3 +109,43 @@ jobs: if: env.GIT_DIFF run: | cd server/v2/cometbft && go test -mod=readonly -race -timeout 30m -tags='ledger test_ledger_mock' + + test-system-v2: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + - uses: actions/setup-go@v5 + with: + go-version: "1.23" + check-latest: true + cache: true + cache-dependency-path: | + simapp/v2/go.sum + systemtest/go.sum + - uses: technote-space/get-diff-action@v6.1.2 + id: git_diff + with: + PATTERNS: | + **/*.go + go.mod + go.sum + **/go.mod + **/go.sum + **/Makefile + Makefile + - name: Install musl lib for simd (docker) binary + if: env.GIT_DIFF + run: | + sudo apt-get install -y musl + - name: system tests v2 + if: env.GIT_DIFF + run: | + COSMOS_BUILD_OPTIONS=v2 make test-system + - uses: actions/upload-artifact@v3 + if: failure() + with: + name: "testnet-setup" + path: ./systemtests/testnet/ + retention-days: 3 diff --git a/CHANGELOG.md b/CHANGELOG.md index ba6219268f7c..f86a2748fdce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,9 +48,11 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (client/keys) [#21829](https://github.com/cosmos/cosmos-sdk/pull/21829) Add support for importing hex key using standard input. * (x/validate) [#21822](https://github.com/cosmos/cosmos-sdk/pull/21822) New module solely responsible for providing ante/post handlers and tx validators for v2. It can be extended by the app developer to provide extra tx validators. * In comparison to x/auth/tx/config, there is no app config to skip ante/post handlers, as overwriting them in baseapp or not injecting the x/validate module has the same effect. +* (baeapp) [#21979](https://github.com/cosmos/cosmos-sdk/pull/21979) Create CheckTxHandler to allow extending the logic of CheckTx. ### Improvements +* (crypto/ledger) [#22116](https://github.com/cosmos/cosmos-sdk/pull/22116) Improve error message when deriving paths using index >100 * (sims) [#21613](https://github.com/cosmos/cosmos-sdk/pull/21613) Add sims2 framework and factory methods for simpler message factories in modules * (modules) [#21963](https://github.com/cosmos/cosmos-sdk/pull/21963) Duplicatable metrics are no more collected in modules. They were unecessary overhead. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 22653e51c334..10b2e3396fac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -270,9 +270,9 @@ When extracting a package to its own go modules, some extra steps are required, ## Protobuf -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. +We use [Protocol Buffers](https://protobuf.dev) along with [gogoproto](https://github.com/cosmos/gogoproto) to generate code for use in Cosmos SDK. -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. +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. For formatting code in `.proto` files, you can run `make proto-format` command. diff --git a/SECURITY.md b/SECURITY.md index 94da755d8f47..30ae0fe0eb74 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -57,13 +57,8 @@ If you follow these guidelines when reporting an issue to us, we commit to: ### More information -* See [TIMELINE.md] for an example timeline of a disclosure. -* See [DISCLOSURE.md] to see more into the inner workings of the disclosure - process. * See [EXAMPLES.md] for some of the examples that we are interested in for the bug bounty program. [h1]: https://hackerone.com/cosmos -[TIMELINE.md]: https://github.com/cosmos/security/blob/main/TIMELINE.md -[DISCLOSURE.md]: https://github.com/cosmos/security/blob/main/DISCLOSURE.md -[EXAMPLES.md]: https://github.com/cosmos/security/blob/main/EXAMPLES.md +[EXAMPLES.md]: https://github.com/interchainio/security/blob/main/resources/CLASSIFICATION_MATRIX.md#real-world-examples diff --git a/baseapp/abci.go b/baseapp/abci.go index f0f24ef52844..dd091294d563 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "sort" + "strconv" "strings" "time" @@ -367,18 +368,27 @@ func (app *BaseApp) CheckTx(req *abci.CheckTxRequest) (*abci.CheckTxResponse, er return nil, fmt.Errorf("unknown RequestCheckTx type: %s", req.Type) } - gInfo, result, anteEvents, err := app.runTx(mode, req.Tx) - if err != nil { - return responseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil + if app.checkTxHandler == nil { + gInfo, result, anteEvents, err := app.runTx(mode, req.Tx, nil) + if err != nil { + return responseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, app.trace), nil + } + + return &abci.CheckTxResponse{ + GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? + GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? + Log: result.Log, + Data: result.Data, + Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), + }, nil } - return &abci.CheckTxResponse{ - GasWanted: int64(gInfo.GasWanted), // TODO: Should type accept unsigned ints? - GasUsed: int64(gInfo.GasUsed), // TODO: Should type accept unsigned ints? - Log: result.Log, - Data: result.Data, - Events: sdk.MarkEventsToIndex(result.Events, app.indexEvents), - }, nil + // Create wrapper to avoid users overriding the execution mode + runTx := func(txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) { + return app.runTx(mode, txBytes, tx) + } + + return app.checkTxHandler(runTx, req) } // PrepareProposal implements the PrepareProposal ABCI method and returns a @@ -822,7 +832,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz // NOTE: Not all raw transactions may adhere to the sdk.Tx interface, e.g. // vote extensions, so skip those. txResults := make([]*abci.ExecTxResult, 0, len(req.Txs)) - for _, rawTx := range req.Txs { + for txIndex, rawTx := range req.Txs { response := app.deliverTx(rawTx) @@ -834,6 +844,12 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz // continue } + // append the tx index to the response.Events + for i, event := range response.Events { + response.Events[i].Attributes = append(event.Attributes, + abci.EventAttribute{Key: "tx_index", Value: strconv.Itoa(txIndex)}) + } + txResults = append(txResults, response) } diff --git a/baseapp/abci_test.go b/baseapp/abci_test.go index fb61080916df..111a86938356 100644 --- a/baseapp/abci_test.go +++ b/baseapp/abci_test.go @@ -676,7 +676,7 @@ func TestABCI_FinalizeBlock_DeliverTx(t *testing.T) { events := res.TxResults[i].GetEvents() require.Len(t, events, 3, "should contain ante handler, message type and counter events respectively") - require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0], events[0], "ante handler event") + require.Equal(t, sdk.MarkEventsToIndex(counterEvent("ante_handler", counter).ToABCIEvents(), map[string]struct{}{})[0].Attributes[0], events[0].Attributes[0], "ante handler event") 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") } diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 89748eadf053..2ef933c205c3 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -91,6 +91,7 @@ type BaseApp struct { prepareCheckStater sdk.PrepareCheckStater // logic to run during commit using the checkState precommiter sdk.Precommiter // logic to run during commit using the deliverState versionModifier server.VersionModifier // interface to get and set the app version + checkTxHandler sdk.CheckTxHandler addrPeerFilter sdk.PeerFilter // filter peers by address and port idPeerFilter sdk.PeerFilter // filter peers by node ID @@ -688,7 +689,6 @@ func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context { // a branched multi-store. func (app *BaseApp) cacheTxContext(ctx sdk.Context, txBytes []byte) (sdk.Context, storetypes.CacheMultiStore) { ms := ctx.MultiStore() - // TODO: https://github.com/cosmos/cosmos-sdk/issues/2824 msCache := ms.CacheMultiStore() if msCache.TracingEnabled() { msCache = msCache.SetTracingContext( @@ -718,6 +718,15 @@ func (app *BaseApp) preBlock(req *abci.FinalizeBlockRequest) ([]abci.Event, erro ctx = ctx.WithBlockGasMeter(gasMeter) app.finalizeBlockState.SetContext(ctx) events = ctx.EventManager().ABCIEvents() + + // append PreBlock attributes to all events + for i, event := range events { + events[i].Attributes = append( + event.Attributes, + abci.EventAttribute{Key: "mode", Value: "PreBlock"}, + abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)}, + ) + } } return events, nil } @@ -739,6 +748,7 @@ func (app *BaseApp) beginBlock(_ *abci.FinalizeBlockRequest) (sdk.BeginBlock, er resp.Events[i].Attributes = append( event.Attributes, abci.EventAttribute{Key: "mode", Value: "BeginBlock"}, + abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)}, ) } @@ -761,7 +771,7 @@ func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult { telemetry.SetGauge(float32(gInfo.GasWanted), "tx", "gas", "wanted") }() - gInfo, result, anteEvents, err := app.runTx(execModeFinalize, tx) + gInfo, result, anteEvents, err := app.runTx(execModeFinalize, tx, nil) if err != nil { resultStr = "failed" resp = responseExecTxResultWithEvents( @@ -801,6 +811,7 @@ func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) { eb.Events[i].Attributes = append( event.Attributes, abci.EventAttribute{Key: "mode", Value: "EndBlock"}, + abci.EventAttribute{Key: "event_index", Value: strconv.Itoa(i)}, ) } @@ -822,7 +833,9 @@ type HasNestedMsgs interface { // Note, gas execution info is always returned. A reference to a Result is // returned if the tx does not run out of gas and if all the messages are valid // and execute successfully. An error is returned otherwise. -func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) { +// both txbytes and the decoded tx are passed to runTx to avoid the state machine encoding the tx and decoding the transaction twice +// passing the decoded tx to runTX is optional, it will be decoded if the tx is nil +func (app *BaseApp) runTx(mode execMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.GasInfo, result *sdk.Result, anteEvents []abci.Event, err error) { // NOTE: GasWanted should be returned by the AnteHandler. GasUsed is // determined by the GasMeter. We need access to the context to get the gas // meter, so we initialize upfront. @@ -870,9 +883,12 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res defer consumeBlockGas() } - tx, err := app.txDecoder(txBytes) - if err != nil { - return sdk.GasInfo{GasUsed: 0, GasWanted: 0}, nil, nil, sdkerrors.ErrTxDecode.Wrap(err.Error()) + // if the transaction is not decoded, decode it here + if tx == nil { + tx, err = app.txDecoder(txBytes) + if err != nil { + return sdk.GasInfo{GasUsed: 0, GasWanted: 0}, nil, nil, sdkerrors.ErrTxDecode.Wrap(err.Error()) + } } msgs := tx.GetMsgs() @@ -1146,6 +1162,12 @@ func createEvents(cdc codec.Codec, events sdk.Events, msg sdk.Msg, reflectMsg pr } } + // append the event_index attribute to all events + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute("event_index", "0")) + for i, event := range events { + events[i] = event.AppendAttributes(sdk.NewAttribute("event_index", strconv.Itoa(i+1))) + } + return sdk.Events{msgEvent}.AppendEvents(events), nil } @@ -1160,7 +1182,7 @@ func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) { return nil, err } - _, _, _, err = app.runTx(execModePrepareProposal, bz) + _, _, _, err = app.runTx(execModePrepareProposal, bz, tx) if err != nil { return nil, err } @@ -1179,7 +1201,7 @@ func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) { return nil, err } - _, _, _, err = app.runTx(execModeProcessProposal, txBz) + _, _, _, err = app.runTx(execModeProcessProposal, txBz, tx) if err != nil { return nil, err } diff --git a/baseapp/options.go b/baseapp/options.go index 53286b2540b9..743d04c5543c 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -367,6 +367,15 @@ func (app *BaseApp) SetPrepareProposal(handler sdk.PrepareProposalHandler) { app.prepareProposal = handler } +// SetCheckTxHandler sets the checkTx function for the BaseApp. +func (app *BaseApp) SetCheckTxHandler(handler sdk.CheckTxHandler) { + if app.sealed { + panic("SetCheckTx() on sealed BaseApp") + } + + app.checkTxHandler = handler +} + func (app *BaseApp) SetExtendVoteHandler(handler sdk.ExtendVoteHandler) { if app.sealed { panic("SetExtendVoteHandler() on sealed BaseApp") diff --git a/baseapp/streaming.go b/baseapp/streaming.go index b6f40cb87fff..3e30f8888d58 100644 --- a/baseapp/streaming.go +++ b/baseapp/streaming.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sort" + "strconv" "strings" abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" @@ -143,21 +144,111 @@ func exposeStoreKeysSorted(keysStr []string, keys map[string]*storetypes.KVStore return exposeStoreKeys } +func eventToAppDataEvent(event abci.Event) (appdata.Event, error) { + appdataEvent := appdata.Event{ + Type: event.Type, + Attributes: func() ([]appdata.EventAttribute, error) { + attrs := make([]appdata.EventAttribute, len(event.Attributes)) + for j, attr := range event.Attributes { + attrs[j] = appdata.EventAttribute{ + Key: attr.Key, + Value: attr.Value, + } + } + return attrs, nil + }, + } + + for _, attr := range event.Attributes { + if attr.Key == "mode" { + switch attr.Value { + case "PreBlock": + appdataEvent.BlockStage = appdata.PreBlockStage + case "BeginBlock": + appdataEvent.BlockStage = appdata.BeginBlockStage + case "EndBlock": + appdataEvent.BlockStage = appdata.EndBlockStage + default: + appdataEvent.BlockStage = appdata.UnknownBlockStage + } + } else if attr.Key == "tx_index" { + txIndex, err := strconv.Atoi(attr.Value) + if err != nil { + return appdata.Event{}, err + } + appdataEvent.TxIndex = int32(txIndex + 1) + appdataEvent.BlockStage = appdata.TxProcessingStage + } else if attr.Key == "msg_index" { + msgIndex, err := strconv.Atoi(attr.Value) + if err != nil { + return appdata.Event{}, err + } + appdataEvent.MsgIndex = int32(msgIndex + 1) + } else if attr.Key == "event_index" { + eventIndex, err := strconv.Atoi(attr.Value) + if err != nil { + return appdata.Event{}, err + } + appdataEvent.EventIndex = int32(eventIndex + 1) + } + } + + return appdataEvent, nil +} + type listenerWrapper struct { listener appdata.Listener } +// NewListenerWrapper creates a new listenerWrapper. +// It is only used for testing purposes. +func NewListenerWrapper(listener appdata.Listener) listenerWrapper { + return listenerWrapper{listener: listener} +} + func (p listenerWrapper) ListenFinalizeBlock(_ context.Context, req abci.FinalizeBlockRequest, res abci.FinalizeBlockResponse) error { if p.listener.StartBlock != nil { - err := p.listener.StartBlock(appdata.StartBlockData{ - Height: uint64(req.Height), - }) - if err != nil { + if err := p.listener.StartBlock(appdata.StartBlockData{ + Height: uint64(req.Height), + HeaderBytes: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + HeaderJSON: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + }); err != nil { + return err + } + } + if p.listener.OnTx != nil { + for i, tx := range req.Txs { + if err := p.listener.OnTx(appdata.TxData{ + TxIndex: int32(i), + Bytes: func() ([]byte, error) { return tx, nil }, + JSON: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + }); err != nil { + return err + } + } + } + if p.listener.OnEvent != nil { + events := make([]appdata.Event, len(res.Events)) + var err error + for i, event := range res.Events { + events[i], err = eventToAppDataEvent(event) + if err != nil { + return err + } + } + for _, txResult := range res.TxResults { + for _, event := range txResult.Events { + appdataEvent, err := eventToAppDataEvent(event) + if err != nil { + return err + } + events = append(events, appdataEvent) + } + } + if err := p.listener.OnEvent(appdata.EventData{Events: events}); err != nil { return err } } - - //// TODO txs, events return nil } diff --git a/baseapp/streaming_test.go b/baseapp/streaming_test.go index b0779c6b91ca..cb3c065be31f 100644 --- a/baseapp/streaming_test.go +++ b/baseapp/streaming_test.go @@ -9,10 +9,12 @@ import ( tmproto "github.com/cometbft/cometbft/api/cometbft/types/v1" "github.com/stretchr/testify/require" + "cosmossdk.io/schema/appdata" storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/baseapp" baseapptestutil "github.com/cosmos/cosmos-sdk/baseapp/testutil" + sdk "github.com/cosmos/cosmos-sdk/types" ) var _ storetypes.ABCIListener = (*MockABCIListener)(nil) @@ -146,3 +148,186 @@ func Test_Ctx_with_StreamingManager(t *testing.T) { require.NoError(t, err) } } + +type mockAppDataListener struct { + appdata.Listener + + startBlockData []appdata.StartBlockData + txData []appdata.TxData + eventData []appdata.EventData + kvPairData []appdata.KVPairData + commitData []appdata.CommitData +} + +func newMockAppDataListener() *mockAppDataListener { + listener := &mockAppDataListener{} + + // Initialize the Listener with custom behavior to store data + listener.Listener = appdata.Listener{ + StartBlock: func(data appdata.StartBlockData) error { + listener.startBlockData = append(listener.startBlockData, data) // Store StartBlockData + return nil + }, + OnTx: func(data appdata.TxData) error { + listener.txData = append(listener.txData, data) // Store TxData + return nil + }, + OnEvent: func(data appdata.EventData) error { + listener.eventData = append(listener.eventData, data) // Store EventData + return nil + }, + OnKVPair: func(data appdata.KVPairData) error { + listener.kvPairData = append(listener.kvPairData, data) // Store KVPairData + return nil + }, + Commit: func(data appdata.CommitData) (func() error, error) { + listener.commitData = append(listener.commitData, data) // Store CommitData + return nil, nil + }, + } + + return listener +} + +func TestAppDataListener(t *testing.T) { + anteKey := []byte("ante-key") + anteOpt := func(bapp *baseapp.BaseApp) { bapp.SetAnteHandler(anteHandlerTxTest(t, capKey1, anteKey)) } + distOpt := func(bapp *baseapp.BaseApp) { bapp.MountStores(distKey1) } + mockListener := newMockAppDataListener() + streamingManager := storetypes.StreamingManager{ABCIListeners: []storetypes.ABCIListener{baseapp.NewListenerWrapper(mockListener.Listener)}} + streamingManagerOpt := func(bapp *baseapp.BaseApp) { bapp.SetStreamingManager(streamingManager) } + addListenerOpt := func(bapp *baseapp.BaseApp) { bapp.CommitMultiStore().AddListeners([]storetypes.StoreKey{distKey1}) } + + // for event tests + baseappOpts := func(app *baseapp.BaseApp) { + app.SetPreBlocker(func(ctx sdk.Context, req *abci.FinalizeBlockRequest) error { + ctx.EventManager().EmitEvent(sdk.NewEvent("pre-block")) + return nil + }) + app.SetBeginBlocker(func(_ sdk.Context) (sdk.BeginBlock, error) { + return sdk.BeginBlock{ + Events: []abci.Event{ + {Type: "begin-block"}, + }, + }, nil + }) + app.SetEndBlocker(func(_ sdk.Context) (sdk.EndBlock, error) { + return sdk.EndBlock{ + Events: []abci.Event{ + {Type: "end-block"}, + }, + }, nil + }) + } + + suite := NewBaseAppSuite(t, anteOpt, distOpt, streamingManagerOpt, addListenerOpt, baseappOpts) + + _, err := suite.baseApp.InitChain( + &abci.InitChainRequest{ + ConsensusParams: &tmproto.ConsensusParams{}, + }, + ) + require.NoError(t, err) + deliverKey := []byte("deliver-key") + baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), CounterServerImpl{t, capKey1, deliverKey}) + + txCount := 5 + txs := make([][]byte, txCount) + + for i := 0; i < txCount; i++ { + tx := newTxCounter(t, suite.txConfig, suite.ac, int64(i), int64(i)) + + txBytes, err := suite.txConfig.TxEncoder()(tx) + require.NoError(t, err) + + sKey := []byte(fmt.Sprintf("distKey%d", i)) + sVal := []byte(fmt.Sprintf("distVal%d", i)) + store := getFinalizeBlockStateCtx(suite.baseApp).KVStore(distKey1) + store.Set(sKey, sVal) + + txs[i] = txBytes + } + + _, err = suite.baseApp.FinalizeBlock(&abci.FinalizeBlockRequest{Height: 1, Txs: txs}) + require.NoError(t, err) + _, err = suite.baseApp.Commit() + require.NoError(t, err) + + // StartBlockData + require.Len(t, mockListener.startBlockData, 1) + require.Equal(t, uint64(1), mockListener.startBlockData[0].Height) + // TxData + txData := mockListener.txData + require.Len(t, txData, len(txs)) + for i := 0; i < txCount; i++ { + require.Equal(t, int32(i), txData[i].TxIndex) + txBytes, err := txData[i].Bytes() + require.NoError(t, err) + require.Equal(t, txs[i], txBytes) + } + // KVPairData + require.Len(t, mockListener.kvPairData, 1) + updates := mockListener.kvPairData[0].Updates + for i := 0; i < txCount; i++ { + require.Equal(t, []byte(distKey1.Name()), updates[i].Actor) + require.Len(t, updates[i].StateChanges, 1) + sKey := []byte(fmt.Sprintf("distKey%d", i)) + sVal := []byte(fmt.Sprintf("distVal%d", i)) + require.Equal(t, sKey, updates[i].StateChanges[0].Key) + require.Equal(t, sVal, updates[i].StateChanges[0].Value) + } + // CommitData + require.Len(t, mockListener.commitData, 1) + // EventData + require.Len(t, mockListener.eventData, 1) + events := mockListener.eventData[0].Events + require.Len(t, events, 3+txCount*3) + + for i := 0; i < 3; i++ { + require.Equal(t, int32(0), events[i].TxIndex) + require.Equal(t, int32(0), events[i].MsgIndex) + require.Equal(t, int32(1), events[i].EventIndex) + attrs, err := events[i].Attributes() + require.NoError(t, err) + require.Len(t, attrs, 2) + switch i { + case 0: + require.Equal(t, appdata.PreBlockStage, events[i].BlockStage) + require.Equal(t, "pre-block", events[i].Type) + case 1: + require.Equal(t, appdata.BeginBlockStage, events[i].BlockStage) + require.Equal(t, "begin-block", events[i].Type) + case 2: + require.Equal(t, appdata.EndBlockStage, events[i].BlockStage) + require.Equal(t, "end-block", events[i].Type) + } + } + + for i := 3; i < 3+txCount*3; i++ { + require.Equal(t, appdata.TxProcessingStage, events[i].BlockStage) + require.Equal(t, int32(i/3), events[i].TxIndex) + switch i % 3 { + case 0: + require.Equal(t, "ante_handler", events[i].Type) + require.Equal(t, int32(0), events[i].MsgIndex) + require.Equal(t, int32(0), events[i].EventIndex) + attrs, err := events[i].Attributes() + require.NoError(t, err) + require.Len(t, attrs, 2) + case 1: + require.Equal(t, "message", events[i].Type) + require.Equal(t, int32(1), events[i].MsgIndex) + require.Equal(t, int32(1), events[i].EventIndex) + attrs, err := events[i].Attributes() + require.NoError(t, err) + require.Len(t, attrs, 5) + case 2: + require.Equal(t, "message", events[i].Type) + require.Equal(t, int32(1), events[i].MsgIndex) + require.Equal(t, int32(2), events[i].EventIndex) + attrs, err := events[i].Attributes() + require.NoError(t, err) + require.Len(t, attrs, 4) + } + } +} diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index fcd0e55c8447..7cae8e541b7d 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -19,13 +19,13 @@ func (app *BaseApp) SimCheck(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, * return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } - gasInfo, result, _, err := app.runTx(execModeCheck, bz) + gasInfo, result, _, err := app.runTx(execModeCheck, bz, tx) return gasInfo, result, err } // Simulate executes a tx in simulate mode to get result and gas info. func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, error) { - gasInfo, result, _, err := app.runTx(execModeSimulate, txBytes) + gasInfo, result, _, err := app.runTx(execModeSimulate, txBytes, nil) return gasInfo, result, err } @@ -36,7 +36,7 @@ func (app *BaseApp) SimDeliver(txEncoder sdk.TxEncoder, tx sdk.Tx) (sdk.GasInfo, return sdk.GasInfo{}, nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "%s", err) } - gasInfo, result, _, err := app.runTx(execModeFinalize, bz) + gasInfo, result, _, err := app.runTx(execModeFinalize, bz, tx) return gasInfo, result, err } diff --git a/client/keys/migrate.go b/client/keys/migrate.go index 0a9fc78e2143..b2e192dffb93 100644 --- a/client/keys/migrate.go +++ b/client/keys/migrate.go @@ -18,8 +18,6 @@ Otherwise, we try to deserialize it using Amino into LegacyInfo. If this attempt LegacyInfo to Protobuf serialization format and overwrite the keyring entry. If any error occurred, it will be outputted in CLI and migration will be continued until all keys in the keyring DB are exhausted. See https://github.com/cosmos/cosmos-sdk/pull/9695 for more details. - -It is recommended to run in 'dry-run' mode first to verify all key migration material. `, Args: cobra.NoArgs, RunE: runMigrateCmd, diff --git a/client/v2/CHANGELOG.md b/client/v2/CHANGELOG.md index dfd4b8cfb213..a3702845c575 100644 --- a/client/v2/CHANGELOG.md +++ b/client/v2/CHANGELOG.md @@ -42,6 +42,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18626](https://github.com/cosmos/cosmos-sdk/pull/18626) Support for off-chain signing and verification of a file. * [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals. +* [#20623](https://github.com/cosmos/cosmos-sdk/pull/20623) Introduce client/v2 tx factory. +* [#20623](https://github.com/cosmos/cosmos-sdk/pull/20623) Extend client/v2 keyring interface with `KeyType` and `KeyInfo`. ### Improvements diff --git a/client/v2/README.md b/client/v2/README.md index 268798233fcd..b4c2666850ee 100644 --- a/client/v2/README.md +++ b/client/v2/README.md @@ -2,7 +2,9 @@ sidebar_position: 1 --- -# AutoCLI +# Client/v2 + +## AutoCLI :::note Synopsis This document details how to build CLI and REST interfaces for a module. Examples from various Cosmos SDK modules are included. @@ -14,9 +16,9 @@ This document details how to build CLI and REST interfaces for a module. Example ::: -The `autocli` (also known as `client/v2`) package is a [Go library](https://pkg.go.dev/cosmossdk.io/client/v2/autocli) for generating CLI (command line interface) interfaces for Cosmos SDK-based applications. It provides a simple way to add CLI commands to your application by generating them automatically based on your gRPC service definitions. Autocli generates CLI commands and flags directly from your protobuf messages, including options, input parameters, and output parameters. This means that you can easily add a CLI interface to your application without having to manually create and manage commands. +The `autocli` (also known as `client/v2/autocli`) package is a [Go library](https://pkg.go.dev/cosmossdk.io/client/v2/autocli) for generating CLI (command line interface) interfaces for Cosmos SDK-based applications. It provides a simple way to add CLI commands to your application by generating them automatically based on your gRPC service definitions. Autocli generates CLI commands and flags directly from your protobuf messages, including options, input parameters, and output parameters. This means that you can easily add a CLI interface to your application without having to manually create and manage commands. -## Overview +### Overview `autocli` generates CLI commands and flags for each method defined in your gRPC service. By default, it generates commands for each gRPC services. The commands are named based on the name of the service method. @@ -32,7 +34,7 @@ For instance, `autocli` would generate a command named `my-method` for the `MyMe It is possible to customize the generation of transactions and queries by defining options for each service. -## Application Wiring +### Application Wiring Here are the steps to use AutoCLI: @@ -73,7 +75,7 @@ if err := rootCmd.Execute(); err != nil { } ``` -### Keyring +#### Keyring `autocli` uses a keyring for key name resolving names and signing transactions. @@ -100,7 +102,7 @@ keyring.NewAutoCLIKeyring(kb) ::: -## Signing +### Signing `autocli` supports signing transactions with the keyring. The [`cosmos.msg.v1.signer` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) defines the signer field of the message. @@ -110,7 +112,7 @@ This field is automatically filled when using the `--from` flag or defining the AutoCLI currently supports only one signer per transaction. ::: -## Module wiring & Customization +### Module wiring & Customization The `AutoCLIOptions()` method on your module allows to specify custom commands, sub-commands or flags for each service, as it was a `cobra.Command` instance, within the `RpcCommandOptions` struct. Defining such options will customize the behavior of the `autocli` command generation, which by default generates a command for each method in your gRPC service. @@ -131,31 +133,7 @@ AutoCLI can create a gov proposal of any tx by simply setting the `GovProposal` Users can however use the `--no-proposal` flag to disable the proposal creation (which is useful if the authority isn't the gov module on a chain). ::: -### Conventions for the `Use` field in Cobra - -According to the [Cobra documentation](https://pkg.go.dev/github.com/spf13/cobra#Command) the following conventions should be followed for the `Use` field in Cobra commands: - -1. **Required arguments**: - * Should not be enclosed in brackets. They can be enclosed in angle brackets `< >` for clarity. - * Example: `command ` - -2. **Optional arguments**: - * Should be enclosed in square brackets `[ ]`. - * Example: `command [optional_argument]` - -3. **Alternative (mutually exclusive) arguments**: - * Should be enclosed in curly braces `{ }`. - * Example: `command {-a | -b}` for required alternatives. - * Example: `command [-a | -b]` for optional alternatives. - -4. **Multiple arguments**: - * Indicated with `...` after the argument. - * Example: `command argument...` - -5. **Combination of options**: - * Example: `command [-F file | -D dir]... [-f format] profile` - -### Specifying Subcommands +#### Specifying Subcommands By default, `autocli` generates a command for each method in your gRPC service. However, you can specify subcommands to group related commands together. To specify subcommands, use the `autocliv1.ServiceCommandDescriptor` struct. @@ -165,7 +143,7 @@ This example shows how to use the `autocliv1.ServiceCommandDescriptor` struct to https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-beta.0/x/gov/autocli.go#L94-L97 ``` -### Positional Arguments +#### Positional Arguments By default `autocli` generates a flag for each field in your protobuf message. However, you can choose to use positional arguments instead of flags for certain fields. @@ -183,7 +161,7 @@ Then the command can be used as follows, instead of having to specify the `--add query auth account cosmos1abcd...xyz ``` -### Customising Flag Names +#### Customising Flag Names By default, `autocli` generates flag names based on the names of the fields in your protobuf message. However, you can customise the flag names by providing a `FlagOptions`. This parameter allows you to specify custom names for flags based on the names of the message fields. @@ -200,7 +178,7 @@ autocliv1.RpcCommandOptions{ `FlagsOptions` is defined like sub commands in the `AutoCLIOptions()` method on your module. -### Combining AutoCLI with Other Commands Within A Module +#### Combining AutoCLI with Other Commands Within A Module AutoCLI can be used alongside other commands within a module. For example, the `gov` module uses AutoCLI to generate commands for the `query` subcommand, but also defines custom commands for the `proposer` subcommands. @@ -212,7 +190,7 @@ https://github.com/cosmos/cosmos-sdk/blob/fa4d87ef7e6d87aaccc94c337ffd2fe90fcb7a If not set to true, `AutoCLI` will not generate commands for the module if there are already commands registered for the module (when `GetTxCmd()` or `GetQueryCmd()` are defined). -### Skip a command +#### Skip a command AutoCLI automatically skips unsupported commands when [`cosmos_proto.method_added_in` protobuf annotation](https://docs.cosmos.network/main/build/building-modules/protobuf-annotations) is present. @@ -225,7 +203,7 @@ Additionally, a command can be manually skipped using the `autocliv1.RpcCommandO } ``` -### Use AutoCLI for non module commands +#### Use AutoCLI for non module commands It is possible to use `AutoCLI` for non module commands. The trick is still to implement the `appmodule.Module` interface and append it to the `appOptions.ModuleOptions` map. @@ -235,7 +213,31 @@ For example, here is how the SDK does it for `cometbft` gRPC commands: https://github.com/cosmos/cosmos-sdk/blob/main/client/grpc/cmtservice/autocli.go#L52-L71 ``` -## Summary +#### Conventions for the `Use` field in Cobra + +According to the [Cobra documentation](https://pkg.go.dev/github.com/spf13/cobra#Command) the following conventions should be followed for the `Use` field in Cobra commands: + +1. **Required arguments**: + * Should not be enclosed in brackets. They can be enclosed in angle brackets `< >` for clarity. + * Example: `command ` + +2. **Optional arguments**: + * Should be enclosed in square brackets `[ ]`. + * Example: `command [optional_argument]` + +3. **Alternative (mutually exclusive) arguments**: + * Should be enclosed in curly braces `{ }`. + * Example: `command {-a | -b}` for required alternatives. + * Example: `command [-a | -b]` for optional alternatives. + +4. **Multiple arguments**: + * Indicated with `...` after the argument. + * Example: `command argument...` + +5. **Combination of options**: + * Example: `command [-F file | -D dir]... [-f format] profile` + +### Summary `autocli` lets you generate CLI to your Cosmos SDK-based applications without any cobra boilerplate. It allows you to easily generate CLI commands and flags from your protobuf messages, and provides many options for customising the behavior of your CLI application. @@ -245,7 +247,7 @@ For more information on `hubl`, including how to configure a new chain and query # Off-Chain -Off-chain functionalities allow you to sign and verify files with two commands: +Off-chain is a `client/v2` package providing functionalities for allowing to sign and verify files with two commands: * `sign-file` for signing a file. * `verify-file` for verifying a previously signed file. @@ -275,6 +277,7 @@ The `encoding` flag lets you choose how the contents of the file should be encod "signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu", "data": "Hello World!\n" } + ``` * `simd off-chain sign-file alice myFile.json --encoding base64` @@ -286,6 +289,7 @@ The `encoding` flag lets you choose how the contents of the file should be encod "signer": "cosmos1x33fy6rusfprkntvjsfregss7rvsvyy4lkwrqu", "data": "SGVsbG8gV29ybGQhCg==" } + ``` * `simd off-chain sign-file alice myFile.json --encoding hex` diff --git a/client/v2/autocli/flag/address.go b/client/v2/autocli/flag/address.go index 58108d094990..454c30a317dd 100644 --- a/client/v2/autocli/flag/address.go +++ b/client/v2/autocli/flag/address.go @@ -151,7 +151,7 @@ func getKeyringFromCtx(ctx *context.Context) keyring.Keyring { dctx := *ctx if dctx != nil { if clientCtx := dctx.Value(client.ClientContextKey); clientCtx != nil { - k, err := sdkkeyring.NewAutoCLIKeyring(clientCtx.(*client.Context).Keyring) + k, err := sdkkeyring.NewAutoCLIKeyring(clientCtx.(*client.Context).Keyring, clientCtx.(*client.Context).AddressCodec) if err != nil { panic(fmt.Errorf("failed to create keyring: %w", err)) } diff --git a/client/v2/autocli/keyring/interface.go b/client/v2/autocli/keyring/interface.go index fa448bd20599..7f2fee1b3e3d 100644 --- a/client/v2/autocli/keyring/interface.go +++ b/client/v2/autocli/keyring/interface.go @@ -20,4 +20,10 @@ type Keyring interface { // Sign signs the given bytes with the key with the given name. Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) + + // KeyType returns the type of the key. + KeyType(name string) (uint, error) + + // KeyInfo given a key name or address returns key name, key address and key type. + KeyInfo(nameOrAddr string) (string, string, uint, error) } diff --git a/client/v2/autocli/keyring/keyring.go b/client/v2/autocli/keyring/keyring.go index 70c2d27d08ed..f5dce25efceb 100644 --- a/client/v2/autocli/keyring/keyring.go +++ b/client/v2/autocli/keyring/keyring.go @@ -48,3 +48,13 @@ func (k *KeyringImpl) LookupAddressByKeyName(name string) ([]byte, error) { func (k *KeyringImpl) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { return k.k.Sign(name, msg, signMode) } + +// KeyType returns the type of the key. +func (k *KeyringImpl) KeyType(name string) (uint, error) { + return k.k.KeyType(name) +} + +// KeyInfo given a key name or address returns key name, key address and key type. +func (k *KeyringImpl) KeyInfo(nameOrAddr string) (string, string, uint, error) { + return k.k.KeyInfo(nameOrAddr) +} diff --git a/client/v2/autocli/keyring/no_keyring.go b/client/v2/autocli/keyring/no_keyring.go index e14267cee5e3..7f0be9c7593e 100644 --- a/client/v2/autocli/keyring/no_keyring.go +++ b/client/v2/autocli/keyring/no_keyring.go @@ -29,3 +29,11 @@ func (k NoKeyring) GetPubKey(name string) (cryptotypes.PubKey, error) { func (k NoKeyring) Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) { return nil, errNoKeyring } + +func (k NoKeyring) KeyType(name string) (uint, error) { + return 0, errNoKeyring +} + +func (k NoKeyring) KeyInfo(name string) (string, string, uint, error) { + return "", "", 0, errNoKeyring +} diff --git a/client/v2/go.mod b/client/v2/go.mod index 0a0c297f21e6..b999f9c15ba5 100644 --- a/client/v2/go.mod +++ b/client/v2/go.mod @@ -53,7 +53,7 @@ require ( github.com/cosmos/btcutil v1.0.5 // indirect github.com/cosmos/cosmos-db v1.0.3-0.20240911104526-ddc3f09bfc22 // indirect github.com/cosmos/crypto v0.1.2 // indirect - github.com/cosmos/go-bip39 v1.0.0 // indirect + github.com/cosmos/go-bip39 v1.0.0 github.com/cosmos/gogogateway v1.2.0 // indirect github.com/cosmos/gogoproto v1.7.0 github.com/cosmos/iavl v1.3.0 // indirect @@ -127,7 +127,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/client/v2/go.sum b/client/v2/go.sum index cf07d8d99a45..1a32ea6bc6f2 100644 --- a/client/v2/go.sum +++ b/client/v2/go.sum @@ -424,8 +424,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/client/v2/internal/account/retriever.go b/client/v2/internal/account/retriever.go new file mode 100644 index 000000000000..2cef69f92cf8 --- /dev/null +++ b/client/v2/internal/account/retriever.go @@ -0,0 +1,116 @@ +package account + +import ( + "context" + "fmt" + "strconv" + + gogogrpc "github.com/cosmos/gogoproto/grpc" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + + "cosmossdk.io/core/address" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +// GRPCBlockHeightHeader represents the gRPC header for block height. +const GRPCBlockHeightHeader = "x-cosmos-block-height" + +var _ AccountRetriever = accountRetriever{} + +// Account provides a read-only abstraction over the auth module's AccountI. +type Account interface { + GetAddress() sdk.AccAddress + GetPubKey() cryptotypes.PubKey // can return nil. + GetAccountNumber() uint64 + GetSequence() uint64 +} + +// AccountRetriever defines methods required to retrieve account details necessary for transaction signing. +type AccountRetriever interface { + GetAccount(context.Context, []byte) (Account, error) + GetAccountWithHeight(context.Context, []byte) (Account, int64, error) + EnsureExists(context.Context, []byte) error + GetAccountNumberSequence(context.Context, []byte) (accNum, accSeq uint64, err error) +} + +type accountRetriever struct { + ac address.Codec + conn gogogrpc.ClientConn + registry codectypes.InterfaceRegistry +} + +// NewAccountRetriever creates a new instance of accountRetriever. +func NewAccountRetriever(ac address.Codec, conn gogogrpc.ClientConn, registry codectypes.InterfaceRegistry) *accountRetriever { + return &accountRetriever{ + ac: ac, + conn: conn, + registry: registry, + } +} + +// GetAccount retrieves an account using its address. +func (a accountRetriever) GetAccount(ctx context.Context, addr []byte) (Account, error) { + acc, _, err := a.GetAccountWithHeight(ctx, addr) + return acc, err +} + +// GetAccountWithHeight retrieves an account and its associated block height using the account's address. +func (a accountRetriever) GetAccountWithHeight(ctx context.Context, addr []byte) (Account, int64, error) { + var header metadata.MD + qc := authtypes.NewQueryClient(a.conn) + + addrStr, err := a.ac.BytesToString(addr) + if err != nil { + return nil, 0, err + } + + res, err := qc.Account(ctx, &authtypes.QueryAccountRequest{Address: addrStr}, grpc.Header(&header)) + if err != nil { + return nil, 0, err + } + + blockHeight := header.Get(GRPCBlockHeightHeader) + if len(blockHeight) != 1 { + return nil, 0, fmt.Errorf("unexpected '%s' header length; got %d, expected 1", GRPCBlockHeightHeader, len(blockHeight)) + } + + nBlockHeight, err := strconv.Atoi(blockHeight[0]) + if err != nil { + return nil, 0, fmt.Errorf("failed to parse block height: %w", err) + } + + var acc Account + if err := a.registry.UnpackAny(res.Account, &acc); err != nil { + return nil, 0, err + } + + return acc, int64(nBlockHeight), nil +} + +// EnsureExists checks if an account exists using its address. +func (a accountRetriever) EnsureExists(ctx context.Context, addr []byte) error { + if _, err := a.GetAccount(ctx, addr); err != nil { + return err + } + return nil +} + +// GetAccountNumberSequence retrieves the account number and sequence for an account using its address. +func (a accountRetriever) GetAccountNumberSequence(ctx context.Context, addr []byte) (accNum, accSeq uint64, err error) { + acc, err := a.GetAccount(ctx, addr) + if err != nil { + if status.Code(err) == codes.NotFound { + return 0, 0, nil + } + return 0, 0, err + } + + return acc.GetAccountNumber(), acc.GetSequence(), nil +} diff --git a/client/v2/internal/coins/util.go b/client/v2/internal/coins/util.go new file mode 100644 index 000000000000..1495386713f6 --- /dev/null +++ b/client/v2/internal/coins/util.go @@ -0,0 +1,66 @@ +package coins + +import ( + "errors" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + "cosmossdk.io/math" + + sdk "github.com/cosmos/cosmos-sdk/types" +) + +var ( + _ withAmount = &base.Coin{} + _ withAmount = &base.DecCoin{} +) + +type withAmount interface { + GetAmount() string +} + +// IsZero check if given coins are zero. +func IsZero[T withAmount](coins []T) (bool, error) { + for _, coin := range coins { + amount, ok := math.NewIntFromString(coin.GetAmount()) + if !ok { + return false, errors.New("invalid coin amount") + } + if !amount.IsZero() { + return false, nil + } + } + return true, nil +} + +func ParseDecCoins(coins string) ([]*base.DecCoin, error) { + parsedGasPrices, err := sdk.ParseDecCoins(coins) // TODO: do it here to avoid sdk dependency + if err != nil { + return nil, err + } + + finalGasPrices := make([]*base.DecCoin, len(parsedGasPrices)) + for i, coin := range parsedGasPrices { + finalGasPrices[i] = &base.DecCoin{ + Denom: coin.Denom, + Amount: coin.Amount.String(), + } + } + return finalGasPrices, nil +} + +func ParseCoinsNormalized(coins string) ([]*base.Coin, error) { + parsedFees, err := sdk.ParseCoinsNormalized(coins) // TODO: do it here to avoid sdk dependency + if err != nil { + return nil, err + } + + finalFees := make([]*base.Coin, len(parsedFees)) + for i, coin := range parsedFees { + finalFees[i] = &base.Coin{ + Denom: coin.Denom, + Amount: coin.Amount.String(), + } + } + + return finalFees, nil +} diff --git a/client/v2/internal/coins/util_test.go b/client/v2/internal/coins/util_test.go new file mode 100644 index 000000000000..1ee7f5842920 --- /dev/null +++ b/client/v2/internal/coins/util_test.go @@ -0,0 +1,83 @@ +package coins + +import ( + "testing" + + "github.com/stretchr/testify/require" + + base "cosmossdk.io/api/cosmos/base/v1beta1" +) + +func TestCoinIsZero(t *testing.T) { + type testCase[T withAmount] struct { + name string + coins []T + isZero bool + } + tests := []testCase[*base.Coin]{ + { + name: "not zero coin", + coins: []*base.Coin{ + { + Denom: "stake", + Amount: "100", + }, + }, + isZero: false, + }, + { + name: "zero coin", + coins: []*base.Coin{ + { + Denom: "stake", + Amount: "0", + }, + }, + isZero: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsZero(tt.coins) + require.NoError(t, err) + require.Equal(t, got, tt.isZero) + }) + } +} + +func TestDecCoinIsZero(t *testing.T) { + type testCase[T withAmount] struct { + name string + coins []T + isZero bool + } + tests := []testCase[*base.DecCoin]{ + { + name: "not zero coin", + coins: []*base.DecCoin{ + { + Denom: "stake", + Amount: "100", + }, + }, + isZero: false, + }, + { + name: "zero coin", + coins: []*base.DecCoin{ + { + Denom: "stake", + Amount: "0", + }, + }, + isZero: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := IsZero(tt.coins) + require.NoError(t, err) + require.Equal(t, got, tt.isZero) + }) + } +} diff --git a/client/v2/offchain/sign.go b/client/v2/offchain/sign.go index fd01227ed13e..b36a50c00ca0 100644 --- a/client/v2/offchain/sign.go +++ b/client/v2/offchain/sign.go @@ -63,7 +63,7 @@ func Sign(ctx client.Context, rawBytes []byte, fromName, indent, encoding, outpu // sign signs a digest with provided key and SignMode. func sign(ctx client.Context, fromName, digest string) (*apitx.Tx, error) { - keybase, err := keyring.NewAutoCLIKeyring(ctx.Keyring) + keybase, err := keyring.NewAutoCLIKeyring(ctx.Keyring, ctx.AddressCodec) if err != nil { return nil, err } diff --git a/client/v2/tx/README.md b/client/v2/tx/README.md new file mode 100644 index 000000000000..ffe2fb8fda00 --- /dev/null +++ b/client/v2/tx/README.md @@ -0,0 +1,465 @@ +The tx package provides a robust set of tools for building, signing, and managing transactions in a Cosmos SDK-based blockchain application. + +## Overview + +This package includes several key components: + +1. Transaction Factory +2. Transaction Config +3. Transaction Encoder/Decoder +4. Signature Handling + +## Architecture + +```mermaid +graph TD + A[Client] --> B[Factory] + B --> D[TxConfig] + D --> E[TxEncodingConfig] + D --> F[TxSigningConfig] + B --> G[Tx] + G --> H[Encoder] + G --> I[Decoder] + F --> J[SignModeHandler] + F --> K[SigningContext] + B --> L[AuxTxBuilder] +``` + +## Key Components + +### TxConfig + +`TxConfig` provides configuration for transaction handling, including: + +- Encoding and decoding +- Sign mode handling +- Signature JSON marshaling/unmarshaling + +```mermaid +classDiagram + class TxConfig { + <> + TxEncodingConfig + TxSigningConfig + } + + class TxEncodingConfig { + <> + TxEncoder() txEncoder + TxDecoder() txDecoder + TxJSONEncoder() txEncoder + TxJSONDecoder() txDecoder + Decoder() Decoder + } + + class TxSigningConfig { + <> + SignModeHandler() *signing.HandlerMap + SigningContext() *signing.Context + MarshalSignatureJSON([]Signature) ([]byte, error) + UnmarshalSignatureJSON([]byte) ([]Signature, error) + } + + class txConfig { + TxEncodingConfig + TxSigningConfig + } + + class defaultEncodingConfig { + cdc codec.BinaryCodec + decoder Decoder + TxEncoder() txEncoder + TxDecoder() txDecoder + TxJSONEncoder() txEncoder + TxJSONDecoder() txDecoder + } + + class defaultTxSigningConfig { + signingCtx *signing.Context + handlerMap *signing.HandlerMap + cdc codec.BinaryCodec + SignModeHandler() *signing.HandlerMap + SigningContext() *signing.Context + MarshalSignatureJSON([]Signature) ([]byte, error) + UnmarshalSignatureJSON([]byte) ([]Signature, error) + } + + TxConfig <|-- txConfig + TxEncodingConfig <|.. defaultEncodingConfig + TxSigningConfig <|.. defaultTxSigningConfig + txConfig *-- defaultEncodingConfig + txConfig *-- defaultTxSigningConfig +``` + +### Factory + +The `Factory` is the main entry point for creating and managing transactions. It handles: + +- Account preparation +- Gas calculation +- Unsigned transaction building +- Transaction signing +- Transaction simulation +- Transaction broadcasting + +```mermaid +classDiagram + class Factory { + keybase keyring.Keyring + cdc codec.BinaryCodec + accountRetriever account.AccountRetriever + ac address.Codec + conn gogogrpc.ClientConn + txConfig TxConfig + txParams TxParameters + tx txState + + NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, parameters) Factory + Prepare() error + BuildUnsignedTx(msgs ...transaction.Msg) error + BuildsSignedTx(ctx context.Context, msgs ...transaction.Msg) (Tx, error) + calculateGas(msgs ...transaction.Msg) error + Simulate(msgs ...transaction.Msg) (*apitx.SimulateResponse, uint64, error) + UnsignedTxString(msgs ...transaction.Msg) (string, error) + BuildSimTx(msgs ...transaction.Msg) ([]byte, error) + sign(ctx context.Context, overwriteSig bool) (Tx, error) + WithGas(gas uint64) + WithSequence(sequence uint64) + WithAccountNumber(accnum uint64) + getTx() (Tx, error) + getFee() (*apitx.Fee, error) + getSigningTxData() (signing.TxData, error) + setSignatures(...Signature) error + } + + class TxParameters { + <> + chainID string + AccountConfig + GasConfig + FeeConfig + SignModeConfig + TimeoutConfig + MemoConfig + } + + class TxConfig { + <> + } + + class Tx { + <> + } + + class txState { + <> + msgs []transaction.Msg + memo string + fees []*base.Coin + gasLimit uint64 + feeGranter []byte + feePayer []byte + timeoutHeight uint64 + unordered bool + timeoutTimestamp uint64 + signatures []Signature + signerInfos []*apitx.SignerInfo + } + + Factory *-- TxParameters + Factory *-- TxConfig + Factory *-- txState + Factory ..> Tx : creates +``` + +### Encoder/Decoder + +The package includes functions for encoding and decoding transactions in both binary and JSON formats. + +```mermaid +classDiagram + class Decoder { + <> + Decode(txBytes []byte) (*txdecode.DecodedTx, error) + } + + class txDecoder { + <> + decode(txBytes []byte) (Tx, error) + } + + class txEncoder { + <> + encode(tx Tx) ([]byte, error) + } + + class EncoderUtils { + <> + decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder + encodeTx(tx Tx) ([]byte, error) + decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder + encodeJsonTx(tx Tx) ([]byte, error) + protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) + } + + class MarshalOptions { + <> + Deterministic bool + } + + class JSONMarshalOptions { + <> + Indent string + UseProtoNames bool + UseEnumNumbers bool + } + + Decoder <.. EncoderUtils : uses + txDecoder <.. EncoderUtils : creates + txEncoder <.. EncoderUtils : implements + EncoderUtils ..> MarshalOptions : uses + EncoderUtils ..> JSONMarshalOptions : uses +``` + +### Sequence Diagrams + +#### Generate Aux Signer Data +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant generateAuxSignerData + participant makeAuxSignerData + participant AuxTxBuilder + participant ctx.PrintProto + + User->>GenerateOrBroadcastTxCLI: Call with isAux flag + GenerateOrBroadcastTxCLI->>generateAuxSignerData: Call + + generateAuxSignerData->>makeAuxSignerData: Call + makeAuxSignerData->>AuxTxBuilder: NewAuxTxBuilder() + + makeAuxSignerData->>AuxTxBuilder: SetAddress(f.txParams.fromAddress) + + alt f.txParams.offline + makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(f.AccountNumber()) + makeAuxSignerData->>AuxTxBuilder: SetSequence(f.Sequence()) + else + makeAuxSignerData->>f.accountRetriever: GetAccountNumberSequence() + makeAuxSignerData->>AuxTxBuilder: SetAccountNumber(accNum) + makeAuxSignerData->>AuxTxBuilder: SetSequence(seq) + end + + makeAuxSignerData->>AuxTxBuilder: SetMsgs(msgs...) + makeAuxSignerData->>AuxTxBuilder: SetSignMode(f.SignMode()) + + makeAuxSignerData->>f.keybase: GetPubKey(f.txParams.fromName) + makeAuxSignerData->>AuxTxBuilder: SetPubKey(pubKey) + + makeAuxSignerData->>AuxTxBuilder: SetChainID(f.txParams.chainID) + makeAuxSignerData->>AuxTxBuilder: GetSignBytes() + + makeAuxSignerData->>f.keybase: Sign(f.txParams.fromName, signBz, f.SignMode()) + makeAuxSignerData->>AuxTxBuilder: SetSignature(sig) + + makeAuxSignerData->>AuxTxBuilder: GetAuxSignerData() + AuxTxBuilder-->>makeAuxSignerData: Return AuxSignerData + makeAuxSignerData-->>generateAuxSignerData: Return AuxSignerData + + generateAuxSignerData->>ctx.PrintProto: Print AuxSignerData + ctx.PrintProto-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### Generate Only +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant generateOnly + participant Factory + participant ctx.PrintString + + User->>GenerateOrBroadcastTxCLI: Call with generateOnly flag + GenerateOrBroadcastTxCLI->>generateOnly: Call + + generateOnly->>Factory: Prepare() + alt Error in Prepare + Factory-->>generateOnly: Return error + generateOnly-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + generateOnly->>Factory: UnsignedTxString(msgs...) + Factory->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: setMsgs(msgs...) + Factory->>Factory: setMemo(f.txParams.memo) + Factory->>Factory: setFees(f.txParams.gasPrices) + Factory->>Factory: setGasLimit(f.txParams.gas) + Factory->>Factory: setFeeGranter(f.txParams.feeGranter) + Factory->>Factory: setFeePayer(f.txParams.feePayer) + Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) + + Factory->>Factory: getTx() + Factory->>Factory: txConfig.TxJSONEncoder() + Factory->>Factory: encoder(tx) + + Factory-->>generateOnly: Return unsigned tx string + generateOnly->>ctx.PrintString: Print unsigned tx string + ctx.PrintString-->>generateOnly: Return result + generateOnly-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### DryRun +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant dryRun + participant Factory + participant os.Stderr + + User->>GenerateOrBroadcastTxCLI: Call with dryRun flag + GenerateOrBroadcastTxCLI->>dryRun: Call + + dryRun->>Factory: Prepare() + alt Error in Prepare + Factory-->>dryRun: Return error + dryRun-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + dryRun->>Factory: Simulate(msgs...) + Factory->>Factory: BuildSimTx(msgs...) + Factory->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: getSimPK() + Factory->>Factory: getSimSignatureData(pk) + Factory->>Factory: setSignatures(sig) + Factory->>Factory: getTx() + Factory->>Factory: txConfig.TxEncoder()(tx) + + Factory->>ServiceClient: Simulate(context.Background(), &apitx.SimulateRequest{}) + ServiceClient->>Factory: Return result + + Factory-->>dryRun: Return (simulation, gas, error) + alt Error in Simulate + dryRun-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + dryRun->>os.Stderr: Fprintf(GasEstimateResponse{GasEstimate: gas}) + os.Stderr-->>dryRun: Return result + dryRun-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +#### Generate and Broadcast Tx +```mermaid +sequenceDiagram + participant User + participant GenerateOrBroadcastTxCLI + participant BroadcastTx + participant Factory + participant clientCtx + + User->>GenerateOrBroadcastTxCLI: Call + GenerateOrBroadcastTxCLI->>BroadcastTx: Call + + BroadcastTx->>Factory: Prepare() + alt Error in Prepare + Factory-->>BroadcastTx: Return error + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + alt SimulateAndExecute is true + BroadcastTx->>Factory: calculateGas(msgs...) + Factory->>Factory: Simulate(msgs...) + Factory->>Factory: WithGas(adjusted) + end + + BroadcastTx->>Factory: BuildUnsignedTx(msgs...) + Factory->>Factory: setMsgs(msgs...) + Factory->>Factory: setMemo(f.txParams.memo) + Factory->>Factory: setFees(f.txParams.gasPrices) + Factory->>Factory: setGasLimit(f.txParams.gas) + Factory->>Factory: setFeeGranter(f.txParams.feeGranter) + Factory->>Factory: setFeePayer(f.txParams.feePayer) + Factory->>Factory: setTimeoutHeight(f.txParams.timeoutHeight) + + alt !clientCtx.SkipConfirm + BroadcastTx->>Factory: getTx() + BroadcastTx->>Factory: txConfig.TxJSONEncoder() + BroadcastTx->>clientCtx: PrintRaw(txBytes) + BroadcastTx->>clientCtx: Input.GetConfirmation() + alt Not confirmed + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + end + + BroadcastTx->>Factory: BuildsSignedTx(ctx, msgs...) + Factory->>Factory: sign(ctx, true) + Factory->>Factory: keybase.GetPubKey(fromName) + Factory->>Factory: getSignBytesAdapter() + Factory->>Factory: keybase.Sign(fromName, bytesToSign, signMode) + Factory->>Factory: setSignatures(sig) + Factory->>Factory: getTx() + + BroadcastTx->>Factory: txConfig.TxEncoder() + BroadcastTx->>clientCtx: BroadcastTx(txBytes) + + alt Error in BroadcastTx + clientCtx-->>BroadcastTx: Return error + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return error + GenerateOrBroadcastTxCLI-->>User: Return error + end + + BroadcastTx->>clientCtx: OutputTx(res) + clientCtx-->>BroadcastTx: Return result + BroadcastTx-->>GenerateOrBroadcastTxCLI: Return result + GenerateOrBroadcastTxCLI-->>User: Return result +``` + +## Usage + +To use the `tx` package, typically you would: + +1. Create a `Factory` +2. Simulate the transaction (optional) +3. Build a signed transaction +4. Encode the transaction +5. Broadcast the transaction + +Here's a simplified example: + +```go +// Create a Factory +factory, err := NewFactory(keybase, cdc, accountRetriever, txConfig, addressCodec, conn, txParameters) +if err != nil { + return err +} + +// Simulate the transaction (optional) +simRes, gas, err := factory.Simulate(msgs...) +if err != nil { + return err +} +factory.WithGas(gas) + +// Build a signed transaction +signedTx, err := factory.BuildsSignedTx(context.Background(), msgs...) +if err != nil { + return err +} + +// Encode the transaction +txBytes, err := factory.txConfig.TxEncoder()(signedTx) +if err != nil { + return err +} + +// Broadcast the transaction +// (This step depends on your specific client implementation) +``` \ No newline at end of file diff --git a/client/v2/tx/common_test.go b/client/v2/tx/common_test.go new file mode 100644 index 000000000000..3b474e9fef7a --- /dev/null +++ b/client/v2/tx/common_test.go @@ -0,0 +1,116 @@ +package tx + +import ( + "context" + + "google.golang.org/grpc" + + abciv1beta1 "cosmossdk.io/api/cosmos/base/abci/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/internal/account" + txdecode "cosmossdk.io/x/tx/decode" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + addrcodec "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/hd" + cryptoKeyring "github.com/cosmos/cosmos-sdk/crypto/keyring" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + "github.com/cosmos/cosmos-sdk/types" +) + +var ( + cdc = codec.NewProtoCodec(codectypes.NewInterfaceRegistry()) + ac = addrcodec.NewBech32Codec("cosmos") + valCodec = addrcodec.NewBech32Codec("cosmosval") + signingOptions = signing.Options{ + AddressCodec: ac, + ValidatorAddressCodec: valCodec, + } + signingContext, _ = signing.NewContext(signingOptions) + decodeOptions = txdecode.Options{SigningContext: signingContext, ProtoCodec: cdc} + decoder, _ = txdecode.NewDecoder(decodeOptions) + + k = cryptoKeyring.NewInMemory(cdc) + keybase, _ = cryptoKeyring.NewAutoCLIKeyring(k, ac) + txConf, _ = NewTxConfig(ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }) +) + +func setKeyring() keyring.Keyring { + registry := codectypes.NewInterfaceRegistry() + codec2.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + k := cryptoKeyring.NewInMemory(cdc) + _, err := k.NewAccount("alice", "equip will roof matter pink blind book anxiety banner elbow sun young", "", "m/44'/118'/0'/0/0", hd.Secp256k1) + if err != nil { + panic(err) + } + keybase, err := cryptoKeyring.NewAutoCLIKeyring(k, ac) + if err != nil { + panic(err) + } + return keybase +} + +type mockAccount struct { + addr []byte +} + +func (m mockAccount) GetAddress() types.AccAddress { + return m.addr +} + +func (m mockAccount) GetPubKey() cryptotypes.PubKey { + return nil +} + +func (m mockAccount) GetAccountNumber() uint64 { + return 1 +} + +func (m mockAccount) GetSequence() uint64 { + return 0 +} + +type mockAccountRetriever struct{} + +func (m mockAccountRetriever) GetAccount(_ context.Context, address []byte) (account.Account, error) { + return mockAccount{addr: address}, nil +} + +func (m mockAccountRetriever) GetAccountWithHeight(_ context.Context, address []byte) (account.Account, int64, error) { + return mockAccount{addr: address}, 0, nil +} + +func (m mockAccountRetriever) EnsureExists(_ context.Context, _ []byte) error { + return nil +} + +func (m mockAccountRetriever) GetAccountNumberSequence(_ context.Context, _ []byte) (accNum, accSeq uint64, err error) { + return accNum, accSeq, nil +} + +type mockClientConn struct{} + +func (m mockClientConn) Invoke(_ context.Context, _ string, _, reply interface{}, _ ...grpc.CallOption) error { + simResponse := apitx.SimulateResponse{ + GasInfo: &abciv1beta1.GasInfo{ + GasWanted: 10000, + GasUsed: 7500, + }, + Result: nil, + } + *reply.(*apitx.SimulateResponse) = simResponse // nolint:govet // ignore linting error + return nil +} + +func (m mockClientConn) NewStream(_ context.Context, _ *grpc.StreamDesc, _ string, _ ...grpc.CallOption) (grpc.ClientStream, error) { + return nil, nil +} diff --git a/client/v2/tx/config.go b/client/v2/tx/config.go new file mode 100644 index 000000000000..a500f7c9b009 --- /dev/null +++ b/client/v2/tx/config.go @@ -0,0 +1,338 @@ +package tx + +import ( + "errors" + + "google.golang.org/protobuf/encoding/protojson" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/known/anypb" + + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" + txdecode "cosmossdk.io/x/tx/decode" + "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + "cosmossdk.io/x/tx/signing/direct" + "cosmossdk.io/x/tx/signing/directaux" + "cosmossdk.io/x/tx/signing/textual" + + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +var ( + _ TxConfig = txConfig{} + _ TxEncodingConfig = defaultEncodingConfig{} + _ TxSigningConfig = defaultTxSigningConfig{} + + defaultEnabledSignModes = []apitxsigning.SignMode{ + apitxsigning.SignMode_SIGN_MODE_DIRECT, + apitxsigning.SignMode_SIGN_MODE_DIRECT_AUX, + apitxsigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + } +) + +// TxConfig is an interface that a client can use to generate a concrete transaction type +// defined by the application. +type TxConfig interface { + TxEncodingConfig + TxSigningConfig +} + +// TxEncodingConfig defines the interface for transaction encoding and decoding. +// It provides methods for both binary and JSON encoding/decoding. +type TxEncodingConfig interface { + // TxEncoder returns an encoder for binary transaction encoding. + TxEncoder() txEncoder + // TxDecoder returns a decoder for binary transaction decoding. + TxDecoder() txDecoder + // TxJSONEncoder returns an encoder for JSON transaction encoding. + TxJSONEncoder() txEncoder + // TxJSONDecoder returns a decoder for JSON transaction decoding. + TxJSONDecoder() txDecoder + // Decoder returns the Decoder interface for decoding transaction bytes into a DecodedTx. + Decoder() Decoder +} + +// TxSigningConfig defines the interface for transaction signing configurations. +type TxSigningConfig interface { + // SignModeHandler returns a reference to the HandlerMap which manages the different signing modes. + SignModeHandler() *signing.HandlerMap + // SigningContext returns a reference to the Context which holds additional data required during signing. + SigningContext() *signing.Context + // MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. + MarshalSignatureJSON([]Signature) ([]byte, error) + // UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. + UnmarshalSignatureJSON([]byte) ([]Signature, error) +} + +// ConfigOptions defines the configuration options for transaction processing. +type ConfigOptions struct { + AddressCodec address.Codec + Decoder Decoder + Cdc codec.BinaryCodec + + ValidatorAddressCodec address.Codec + FileResolver signing.ProtoFileResolver + TypeResolver signing.TypeResolver + CustomGetSigner map[protoreflect.FullName]signing.GetSignersFunc + MaxRecursionDepth int + + EnablesSignModes []apitxsigning.SignMode + CustomSignModes []signing.SignModeHandler + TextualCoinMetadataQueryFn textual.CoinMetadataQueryFn +} + +// validate checks the ConfigOptions for required fields and sets default values where necessary. +// It returns an error if any required field is missing. +func (c *ConfigOptions) validate() error { + if c.AddressCodec == nil { + return errors.New("address codec cannot be nil") + } + if c.Cdc == nil { + return errors.New("codec cannot be nil") + } + if c.ValidatorAddressCodec == nil { + return errors.New("validator address codec cannot be nil") + } + + // set default signModes if none are provided + if len(c.EnablesSignModes) == 0 { + c.EnablesSignModes = defaultEnabledSignModes + } + return nil +} + +// txConfig is a struct that embeds TxEncodingConfig and TxSigningConfig interfaces. +type txConfig struct { + TxEncodingConfig + TxSigningConfig +} + +// NewTxConfig creates a new TxConfig instance using the provided ConfigOptions. +// It validates the options, initializes the signing context, and sets up the decoder if not provided. +func NewTxConfig(options ConfigOptions) (TxConfig, error) { + err := options.validate() + if err != nil { + return nil, err + } + + signingCtx, err := newDefaultTxSigningConfig(options) + if err != nil { + return nil, err + } + + if options.Decoder == nil { + options.Decoder, err = txdecode.NewDecoder(txdecode.Options{ + SigningContext: signingCtx.SigningContext(), + ProtoCodec: options.Cdc, + }) + if err != nil { + return nil, err + } + } + + return &txConfig{ + TxEncodingConfig: defaultEncodingConfig{ + cdc: options.Cdc, + decoder: options.Decoder, + }, + TxSigningConfig: signingCtx, + }, nil +} + +// defaultEncodingConfig is an empty struct that implements the TxEncodingConfig interface. +type defaultEncodingConfig struct { + cdc codec.BinaryCodec + decoder Decoder +} + +// TxEncoder returns the default transaction encoder. +func (t defaultEncodingConfig) TxEncoder() txEncoder { + return encodeTx +} + +// TxDecoder returns the default transaction decoder. +func (t defaultEncodingConfig) TxDecoder() txDecoder { + return decodeTx(t.cdc, t.decoder) +} + +// TxJSONEncoder returns the default JSON transaction encoder. +func (t defaultEncodingConfig) TxJSONEncoder() txEncoder { + return encodeJsonTx +} + +// TxJSONDecoder returns the default JSON transaction decoder. +func (t defaultEncodingConfig) TxJSONDecoder() txDecoder { + return decodeJsonTx(t.cdc, t.decoder) +} + +// Decoder returns the Decoder instance associated with this encoding configuration. +func (t defaultEncodingConfig) Decoder() Decoder { + return t.decoder +} + +// defaultTxSigningConfig is a struct that holds the signing context and handler map. +type defaultTxSigningConfig struct { + signingCtx *signing.Context + handlerMap *signing.HandlerMap + cdc codec.BinaryCodec +} + +// newDefaultTxSigningConfig creates a new defaultTxSigningConfig instance using the provided ConfigOptions. +// It initializes the signing context and handler map. +func newDefaultTxSigningConfig(opts ConfigOptions) (*defaultTxSigningConfig, error) { + signingCtx, err := newSigningContext(opts) + if err != nil { + return nil, err + } + + handlerMap, err := newHandlerMap(opts, signingCtx) + if err != nil { + return nil, err + } + + return &defaultTxSigningConfig{ + signingCtx: signingCtx, + handlerMap: handlerMap, + cdc: opts.Cdc, + }, nil +} + +// SignModeHandler returns the handler map that manages the different signing modes. +func (t defaultTxSigningConfig) SignModeHandler() *signing.HandlerMap { + return t.handlerMap +} + +// SigningContext returns the signing context that holds additional data required during signing. +func (t defaultTxSigningConfig) SigningContext() *signing.Context { + return t.signingCtx +} + +// MarshalSignatureJSON takes a slice of Signature objects and returns their JSON encoding. +// This method is not yet implemented and will panic if called. +func (t defaultTxSigningConfig) MarshalSignatureJSON(signatures []Signature) ([]byte, error) { + descriptor := make([]*apitxsigning.SignatureDescriptor, len(signatures)) + + for i, sig := range signatures { + descData, err := signatureDataToProto(sig.Data) + if err != nil { + return nil, err + } + + anyPk, err := codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return nil, err + } + + descriptor[i] = &apitxsigning.SignatureDescriptor{ + PublicKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(sig.PubKey), + Value: anyPk.Value, + }, + Data: descData, + Sequence: sig.Sequence, + } + } + + return jsonMarshalOptions.Marshal(&apitxsigning.SignatureDescriptors{Signatures: descriptor}) +} + +// UnmarshalSignatureJSON takes a JSON byte slice and returns a slice of Signature objects. +// This method is not yet implemented and will panic if called. +func (t defaultTxSigningConfig) UnmarshalSignatureJSON(bz []byte) ([]Signature, error) { + var descriptor apitxsigning.SignatureDescriptors + + err := protojson.UnmarshalOptions{}.Unmarshal(bz, &descriptor) + if err != nil { + return nil, err + } + + sigs := make([]Signature, len(descriptor.Signatures)) + for i, desc := range descriptor.Signatures { + var pubkey cryptotypes.PubKey + + anyPk := &codectypes.Any{ + TypeUrl: desc.PublicKey.TypeUrl, + Value: desc.PublicKey.Value, + } + + err = t.cdc.UnpackAny(anyPk, &pubkey) + if err != nil { + return nil, err + } + + data, err := SignatureDataFromProto(desc.Data) + if err != nil { + return nil, err + } + + sigs[i] = Signature{ + PubKey: pubkey, + Data: data, + Sequence: desc.Sequence, + } + } + + return sigs, nil +} + +// newSigningContext creates a new signing context using the provided ConfigOptions. +// Returns a signing.Context instance or an error if initialization fails. +func newSigningContext(opts ConfigOptions) (*signing.Context, error) { + return signing.NewContext(signing.Options{ + FileResolver: opts.FileResolver, + TypeResolver: opts.TypeResolver, + AddressCodec: opts.AddressCodec, + ValidatorAddressCodec: opts.ValidatorAddressCodec, + CustomGetSigners: opts.CustomGetSigner, + MaxRecursionDepth: opts.MaxRecursionDepth, + }) +} + +// newHandlerMap constructs a new HandlerMap based on the provided ConfigOptions and signing context. +// It initializes handlers for each enabled and custom sign mode specified in the options. +func newHandlerMap(opts ConfigOptions, signingCtx *signing.Context) (*signing.HandlerMap, error) { + lenSignModes := len(opts.EnablesSignModes) + handlers := make([]signing.SignModeHandler, lenSignModes+len(opts.CustomSignModes)) + + for i, m := range opts.EnablesSignModes { + var err error + switch m { + case apitxsigning.SignMode_SIGN_MODE_DIRECT: + handlers[i] = &direct.SignModeHandler{} + case apitxsigning.SignMode_SIGN_MODE_TEXTUAL: + if opts.TextualCoinMetadataQueryFn == nil { + return nil, errors.New("cannot enable SIGN_MODE_TEXTUAL without a TextualCoinMetadataQueryFn") + } + handlers[i], err = textual.NewSignModeHandler(textual.SignModeOptions{ + CoinMetadataQuerier: opts.TextualCoinMetadataQueryFn, + FileResolver: signingCtx.FileResolver(), + TypeResolver: signingCtx.TypeResolver(), + }) + if err != nil { + return nil, err + } + case apitxsigning.SignMode_SIGN_MODE_DIRECT_AUX: + handlers[i], err = directaux.NewSignModeHandler(directaux.SignModeHandlerOptions{ + TypeResolver: signingCtx.TypeResolver(), + SignersContext: signingCtx, + }) + if err != nil { + return nil, err + } + case apitxsigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON: + handlers[i] = aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{ + FileResolver: signingCtx.FileResolver(), + TypeResolver: opts.TypeResolver, + }) + } + } + for i, m := range opts.CustomSignModes { + handlers[i+lenSignModes] = m + } + + handler := signing.NewHandlerMap(handlers...) + return handler, nil +} diff --git a/client/v2/tx/config_test.go b/client/v2/tx/config_test.go new file mode 100644 index 000000000000..7d1f223d1214 --- /dev/null +++ b/client/v2/tx/config_test.go @@ -0,0 +1,293 @@ +package tx + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + _ "cosmossdk.io/api/cosmos/crypto/secp256k1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/x/tx/signing" + + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/address" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + codec2 "github.com/cosmos/cosmos-sdk/crypto/codec" + kmultisig "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +type mockModeHandler struct{} + +func (t mockModeHandler) Mode() apitxsigning.SignMode { + return apitxsigning.SignMode_SIGN_MODE_DIRECT +} + +func (t mockModeHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ signing.TxData) ([]byte, error) { + return []byte{}, nil +} + +func TestConfigOptions_validate(t *testing.T) { + tests := []struct { + name string + opts ConfigOptions + wantErr bool + }{ + { + name: "valid options", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + }, + { + name: "missing address codec", + opts: ConfigOptions{ + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + wantErr: true, + }, + { + name: "missing decoder", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + }, + { + name: "missing codec", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + wantErr: true, + }, + { + name: "missing validator address codec", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + }, + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := tt.opts.validate(); (err != nil) != tt.wantErr { + t.Errorf("validate() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func Test_newHandlerMap(t *testing.T) { + tests := []struct { + name string + opts ConfigOptions + }{ + { + name: "handler map with default sign modes", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + }, + }, + { + name: "handler map with just one sign mode", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + EnablesSignModes: []apitxsigning.SignMode{apitxsigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + { + name: "handler map with custom sign modes", + opts: ConfigOptions{ + AddressCodec: address.NewBech32Codec("cosmos"), + Decoder: decoder, + Cdc: cdc, + ValidatorAddressCodec: address.NewBech32Codec("cosmosvaloper"), + CustomSignModes: []signing.SignModeHandler{mockModeHandler{}}, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := tt.opts.validate() + require.NoError(t, err) + + signingCtx, err := newSigningContext(tt.opts) + require.NoError(t, err) + + handlerMap, err := newHandlerMap(tt.opts, signingCtx) + require.NoError(t, err) + require.NotNil(t, handlerMap) + require.Equal(t, len(handlerMap.SupportedModes()), len(tt.opts.EnablesSignModes)+len(tt.opts.CustomSignModes)) + }) + } +} + +func TestNewTxConfig(t *testing.T) { + tests := []struct { + name string + options ConfigOptions + wantErr bool + }{ + { + name: "valid options", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := NewTxConfig(tt.options) + if (err != nil) != tt.wantErr { + t.Errorf("NewTxConfig() error = %v, wantErr %v", err, tt.wantErr) + return + } + require.NotNil(t, got) + }) + } +} + +func Test_defaultTxSigningConfig_MarshalSignatureJSON(t *testing.T) { + tests := []struct { + name string + options ConfigOptions + signatures func(t *testing.T) []Signature + }{ + { + name: "single signature", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + signatures: func(t *testing.T) []Signature { + t.Helper() + + k := setKeyring() + pk, err := k.GetPubKey("alice") + require.NoError(t, err) + signature, err := k.Sign("alice", make([]byte, 10), apitxsigning.SignMode_SIGN_MODE_DIRECT) + require.NoError(t, err) + return []Signature{ + { + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: signature, + }, + }, + } + }, + }, + { + name: "multisig signatures", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + signatures: func(t *testing.T) []Signature { + t.Helper() + + n := 2 + pubKeys := make([]cryptotypes.PubKey, n) + sigs := make([]SignatureData, n) + for i := 0; i < n; i++ { + sk := secp256k1.GenPrivKey() + pubKeys[i] = sk.PubKey() + msg, err := sk.Sign(make([]byte, 10)) + require.NoError(t, err) + sigs[i] = &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: msg, + } + } + bitArray := cryptotypes.NewCompactBitArray(n) + mKey := kmultisig.NewLegacyAminoPubKey(n, pubKeys) + return []Signature{ + { + PubKey: mKey, + Data: &MultiSignatureData{ + BitArray: &apicrypto.CompactBitArray{ + ExtraBitsStored: bitArray.ExtraBitsStored, + Elems: bitArray.Elems, + }, + Signatures: sigs, + }, + }, + } + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config, err := NewTxConfig(tt.options) + require.NoError(t, err) + + got, err := config.MarshalSignatureJSON(tt.signatures(t)) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func Test_defaultTxSigningConfig_UnmarshalSignatureJSON(t *testing.T) { + registry := codectypes.NewInterfaceRegistry() + codec2.RegisterInterfaces(registry) + cdc := codec.NewProtoCodec(registry) + tests := []struct { + name string + options ConfigOptions + bz []byte + }{ + { + name: "single signature", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.secp256k1.PubKey", "key":"A0/vnNfExjWI07A/61KBudIyy6NNbz1xruWSEf+/4f6H"}, "data":{"single":{"mode":"SIGN_MODE_DIRECT", "signature":"usUTJwdc4PWPuox0Y0G/RuHoxyj+QpUcBGvXyNdDX1FOdoVj0tg4TGKT2NnM3QP6wCNbubjHuMOhTtqfW8SkYg=="}}}]}`), + }, + { + name: "multisig signatures", + options: ConfigOptions{ + AddressCodec: ac, + Cdc: cdc, + ValidatorAddressCodec: valCodec, + }, + bz: []byte(`{"signatures":[{"public_key":{"@type":"/cosmos.crypto.multisig.LegacyAminoPubKey","threshold":2,"public_keys":[{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"A4Bs9huvS/COpZNhVhTnhgc8YR6VrSQ8hLQIHgnA+m3w"},{"@type":"/cosmos.crypto.secp256k1.PubKey","key":"AuNz2lFkLn3sKNjC5r4OWhgkWg5DZpGUiR9OdpzXspnp"}]},"data":{"multi":{"bitarray":{"extra_bits_stored":2,"elems":"AA=="},"signatures":[{"single":{"mode":"SIGN_MODE_DIRECT","signature":"vng4IlPzLH3fDFpikM5y1SfXFGny4BcLGwIFU0Ty4yoWjIxjTS4m6fgDB61sxEkV5DK/CD7gUwenGuEpzJ2IGw=="}},{"single":{"mode":"SIGN_MODE_DIRECT","signature":"2dsGmr13bq/mPxbk9AgqcFpuvk4beszWu6uxkx+EhTMdVGp4J8FtjZc8xs/Pp3oTWY4ScAORYQHxwqN4qwMXGg=="}}]}}}]}`), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + config, err := NewTxConfig(tt.options) + require.NoError(t, err) + + got, err := config.UnmarshalSignatureJSON(tt.bz) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} diff --git a/client/v2/tx/encoder.go b/client/v2/tx/encoder.go new file mode 100644 index 000000000000..2094efe6d3d5 --- /dev/null +++ b/client/v2/tx/encoder.go @@ -0,0 +1,119 @@ +package tx + +import ( + "fmt" + + "google.golang.org/protobuf/encoding/protojson" + protov2 "google.golang.org/protobuf/proto" + + txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" + txdecode "cosmossdk.io/x/tx/decode" + + "github.com/cosmos/cosmos-sdk/codec" +) + +var ( + // marshalOption configures protobuf marshaling to be deterministic. + marshalOption = protov2.MarshalOptions{Deterministic: true} + + // jsonMarshalOptions configures JSON marshaling for protobuf messages. + jsonMarshalOptions = protojson.MarshalOptions{ + Indent: "", + UseProtoNames: true, + UseEnumNumbers: false, + } +) + +// Decoder defines the interface for decoding transaction bytes into a DecodedTx. +type Decoder interface { + Decode(txBytes []byte) (*txdecode.DecodedTx, error) +} + +// txDecoder is a function type that unmarshals transaction bytes into an API Tx type. +type txDecoder func(txBytes []byte) (Tx, error) + +// txEncoder is a function type that marshals a transaction into bytes. +type txEncoder func(tx Tx) ([]byte, error) + +// decodeTx decodes transaction bytes into an apitx.Tx structure. +func decodeTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { + return func(txBytes []byte) (Tx, error) { + tx := new(txv1beta1.Tx) + err := protov2.Unmarshal(txBytes, tx) + if err != nil { + return nil, err + } + + pTxBytes, err := protoTxBytes(tx) + if err != nil { + return nil, err + } + + decodedTx, err := decoder.Decode(pTxBytes) + if err != nil { + return nil, err + } + return newWrapperTx(cdc, decodedTx), nil + } +} + +// encodeTx encodes an apitx.Tx into bytes using protobuf marshaling options. +func encodeTx(tx Tx) ([]byte, error) { + wTx, ok := tx.(*wrappedTx) + if !ok { + return nil, fmt.Errorf("unexpected tx type: %T", tx) + } + return marshalOption.Marshal(wTx.Tx) +} + +// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format. +func decodeJsonTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder { + return func(txBytes []byte) (Tx, error) { + jsonTx := new(txv1beta1.Tx) + err := protojson.UnmarshalOptions{ + AllowPartial: false, + DiscardUnknown: false, + }.Unmarshal(txBytes, jsonTx) + if err != nil { + return nil, err + } + + pTxBytes, err := protoTxBytes(jsonTx) + if err != nil { + return nil, err + } + + decodedTx, err := decoder.Decode(pTxBytes) + if err != nil { + return nil, err + } + return newWrapperTx(cdc, decodedTx), nil + } +} + +// encodeJsonTx encodes an apitx.Tx into bytes using JSON marshaling options. +func encodeJsonTx(tx Tx) ([]byte, error) { + wTx, ok := tx.(*wrappedTx) + if !ok { + return nil, fmt.Errorf("unexpected tx type: %T", tx) + } + return jsonMarshalOptions.Marshal(wTx.Tx) +} + +func protoTxBytes(tx *txv1beta1.Tx) ([]byte, error) { + bodyBytes, err := marshalOption.Marshal(tx.Body) + if err != nil { + return nil, err + } + + authInfoBytes, err := marshalOption.Marshal(tx.AuthInfo) + if err != nil { + return nil, err + } + + return marshalOption.Marshal(&txv1beta1.TxRaw{ + BodyBytes: bodyBytes, + AuthInfoBytes: authInfoBytes, + Signatures: tx.Signatures, + }) +} diff --git a/client/v2/tx/encoder_test.go b/client/v2/tx/encoder_test.go new file mode 100644 index 000000000000..9dec56762318 --- /dev/null +++ b/client/v2/tx/encoder_test.go @@ -0,0 +1,107 @@ +package tx + +import ( + "testing" + + "github.com/stretchr/testify/require" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + countertypes "cosmossdk.io/api/cosmos/counter/v1" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/transaction" + + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" +) + +func getWrappedTx(t *testing.T) *wrappedTx { + t.Helper() + + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := ac.BytesToString(pk.Address()) + + f.tx.msgs = []transaction.Msg{&countertypes.MsgIncreaseCounter{ + Signer: addr, + Count: 0, + }} + require.NoError(t, err) + + err = f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }}...) + require.NoError(t, err) + wTx, err := f.getTx() + require.NoError(t, err) + return wTx +} + +func Test_txEncoder_txDecoder(t *testing.T) { + wTx := getWrappedTx(t) + + encodedTx, err := encodeTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + + isDeterministic, err := encodeTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + require.Equal(t, encodedTx, isDeterministic) + + f := decodeTx(cdc, decoder) + decodedTx, err := f(encodedTx) + require.NoError(t, err) + require.NotNil(t, decodedTx) + + dTx, ok := decodedTx.(*wrappedTx) + require.True(t, ok) + require.Equal(t, wTx.TxRaw, dTx.TxRaw) + require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) + require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) + require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) +} + +func Test_txJsonEncoder_txJsonDecoder(t *testing.T) { + tests := []struct { + name string + }{ + { + name: "json encode and decode tx", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + wTx := getWrappedTx(t) + + encodedTx, err := encodeJsonTx(wTx) + require.NoError(t, err) + require.NotNil(t, encodedTx) + + f := decodeJsonTx(cdc, decoder) + decodedTx, err := f(encodedTx) + require.NoError(t, err) + require.NotNil(t, decodedTx) + + dTx, ok := decodedTx.(*wrappedTx) + require.True(t, ok) + require.Equal(t, wTx.TxRaw, dTx.TxRaw) + require.Equal(t, wTx.Tx.AuthInfo.String(), dTx.Tx.AuthInfo.String()) + require.Equal(t, wTx.Tx.Body.String(), dTx.Tx.Body.String()) + require.Equal(t, wTx.Tx.Signatures, dTx.Tx.Signatures) + }) + } +} diff --git a/client/v2/tx/factory.go b/client/v2/tx/factory.go new file mode 100644 index 000000000000..9dd0eae21a34 --- /dev/null +++ b/client/v2/tx/factory.go @@ -0,0 +1,761 @@ +package tx + +import ( + "context" + "errors" + "fmt" + "math/big" + "strings" + + "github.com/cosmos/go-bip39" + gogogrpc "github.com/cosmos/gogoproto/grpc" + "github.com/spf13/pflag" + "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/timestamppb" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/internal/account" + "cosmossdk.io/client/v2/internal/coins" + "cosmossdk.io/core/address" + "cosmossdk.io/core/transaction" + "cosmossdk.io/math" + "cosmossdk.io/x/tx/signing" + + flags2 "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// Factory defines a client transaction factory that facilitates generating and +// signing an application-specific transaction. +type Factory struct { + keybase keyring.Keyring + cdc codec.BinaryCodec + accountRetriever account.AccountRetriever + ac address.Codec + conn gogogrpc.ClientConn + txConfig TxConfig + txParams TxParameters + + tx txState +} + +func NewFactoryFromFlagSet(flags *pflag.FlagSet, keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, + txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, +) (Factory, error) { + offline, _ := flags.GetBool(flags2.FlagOffline) + if err := validateFlagSet(flags, offline); err != nil { + return Factory{}, err + } + + params, err := txParamsFromFlagSet(flags, keybase, ac) + if err != nil { + return Factory{}, err + } + + params, err = prepareTxParams(params, accRetriever, offline) + if err != nil { + return Factory{}, err + } + + return NewFactory(keybase, cdc, accRetriever, txConfig, ac, conn, params) +} + +// NewFactory returns a new instance of Factory. +func NewFactory(keybase keyring.Keyring, cdc codec.BinaryCodec, accRetriever account.AccountRetriever, + txConfig TxConfig, ac address.Codec, conn gogogrpc.ClientConn, parameters TxParameters, +) (Factory, error) { + return Factory{ + keybase: keybase, + cdc: cdc, + accountRetriever: accRetriever, + ac: ac, + conn: conn, + txConfig: txConfig, + txParams: parameters, + + tx: txState{}, + }, nil +} + +// validateFlagSet checks the provided flags for consistency and requirements based on the operation mode. +func validateFlagSet(flags *pflag.FlagSet, offline bool) error { + if offline { + if !flags.Changed(flags2.FlagAccountNumber) || !flags.Changed(flags2.FlagSequence) { + return errors.New("account-number and sequence must be set in offline mode") + } + + gas, _ := flags.GetString(flags2.FlagGas) + gasSetting, _ := flags2.ParseGasSetting(gas) + if gasSetting.Simulate { + return errors.New("simulate and offline flags cannot be set at the same time") + } + } + + generateOnly, _ := flags.GetBool(flags2.FlagGenerateOnly) + chainID, _ := flags.GetString(flags2.FlagChainID) + if offline && generateOnly && chainID != "" { + return errors.New("chain ID cannot be used when offline and generate-only flags are set") + } + if chainID == "" { + return errors.New("chain ID required but not specified") + } + + dryRun, _ := flags.GetBool(flags2.FlagDryRun) + if offline && dryRun { + return errors.New("dry-run: cannot use offline mode") + } + + return nil +} + +// prepareTxParams ensures the account defined by ctx.GetFromAddress() exists and +// if the account number and/or the account sequence number are zero (not set), +// they will be queried for and set on the provided Factory. +func prepareTxParams(parameters TxParameters, accRetriever account.AccountRetriever, offline bool) (TxParameters, error) { + if offline { + return parameters, nil + } + + if len(parameters.address) == 0 { + return parameters, errors.New("missing 'from address' field") + } + + if parameters.accountNumber == 0 || parameters.sequence == 0 { + num, seq, err := accRetriever.GetAccountNumberSequence(context.Background(), parameters.address) + if err != nil { + return parameters, err + } + + if parameters.accountNumber == 0 { + parameters.accountNumber = num + } + + if parameters.sequence == 0 { + parameters.sequence = seq + } + } + + return parameters, nil +} + +// BuildUnsignedTx builds a transaction to be signed given a set of messages. +// Once created, the fee, memo, and messages are set. +func (f *Factory) BuildUnsignedTx(msgs ...transaction.Msg) error { + fees := f.txParams.fees + + isGasPriceZero, err := coins.IsZero(f.txParams.gasPrices) + if err != nil { + return err + } + if !isGasPriceZero { + areFeesZero, err := coins.IsZero(fees) + if err != nil { + return err + } + if !areFeesZero { + return errors.New("cannot provide both fees and gas prices") + } + + // f.gas is an uint64 and we should convert to LegacyDec + // without the risk of under/overflow via uint64->int64. + glDec := math.LegacyNewDecFromBigInt(new(big.Int).SetUint64(f.txParams.gas)) + + // Derive the fees based on the provided gas prices, where + // fee = ceil(gasPrice * gasLimit). + fees = make([]*base.Coin, len(f.txParams.gasPrices)) + + for i, gp := range f.txParams.gasPrices { + fee, err := math.LegacyNewDecFromStr(gp.Amount) + if err != nil { + return err + } + fee = fee.Mul(glDec) + fees[i] = &base.Coin{Denom: gp.Denom, Amount: fee.Ceil().RoundInt().String()} + } + } + + if err := validateMemo(f.txParams.memo); err != nil { + return err + } + + f.tx.msgs = msgs + f.tx.memo = f.txParams.memo + f.tx.fees = fees + f.tx.gasLimit = f.txParams.gas + f.tx.unordered = f.txParams.unordered + f.tx.timeoutTimestamp = f.txParams.timeoutTimestamp + + err = f.setFeeGranter(f.txParams.feeGranter) + if err != nil { + return err + } + err = f.setFeePayer(f.txParams.feePayer) + if err != nil { + return err + } + + return nil +} + +func (f *Factory) BuildsSignedTx(ctx context.Context, msgs ...transaction.Msg) (Tx, error) { + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return nil, err + } + + return f.sign(ctx, true) +} + +// calculateGas calculates the gas required for the given messages. +func (f *Factory) calculateGas(msgs ...transaction.Msg) error { + _, adjusted, err := f.Simulate(msgs...) + if err != nil { + return err + } + + f.WithGas(adjusted) + + return nil +} + +// Simulate simulates the execution of a transaction and returns the +// simulation response obtained by the query and the adjusted gas amount. +func (f *Factory) Simulate(msgs ...transaction.Msg) (*apitx.SimulateResponse, uint64, error) { + txBytes, err := f.BuildSimTx(msgs...) + if err != nil { + return nil, 0, err + } + + txSvcClient := apitx.NewServiceClient(f.conn) + simRes, err := txSvcClient.Simulate(context.Background(), &apitx.SimulateRequest{ + TxBytes: txBytes, + }) + if err != nil { + return nil, 0, err + } + + return simRes, uint64(f.gasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil +} + +// UnsignedTxString will generate an unsigned transaction and print it to the writer +// specified by ctx.Output. If simulation was requested, the gas will be +// simulated and also printed to the same writer before the transaction is +// printed. +func (f *Factory) UnsignedTxString(msgs ...transaction.Msg) (string, error) { + if f.simulateAndExecute() { + err := f.calculateGas(msgs...) + if err != nil { + return "", err + } + } + + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return "", err + } + + encoder := f.txConfig.TxJSONEncoder() + if encoder == nil { + return "", errors.New("cannot print unsigned tx: tx json encoder is nil") + } + + tx, err := f.getTx() + if err != nil { + return "", err + } + + json, err := encoder(tx) + if err != nil { + return "", err + } + + return fmt.Sprintf("%s\n", json), nil +} + +// BuildSimTx creates an unsigned tx with an empty single signature and returns +// the encoded transaction or an error if the unsigned transaction cannot be +// built. +func (f *Factory) BuildSimTx(msgs ...transaction.Msg) ([]byte, error) { + err := f.BuildUnsignedTx(msgs...) + if err != nil { + return nil, err + } + + pk, err := f.getSimPK() + if err != nil { + return nil, err + } + + // Create an empty signature literal as the ante handler will populate with a + // sentinel pubkey. + sig := Signature{ + PubKey: pk, + Data: f.getSimSignatureData(pk), + Sequence: f.sequence(), + } + if err := f.setSignatures(sig); err != nil { + return nil, err + } + + encoder := f.txConfig.TxEncoder() + if encoder == nil { + return nil, fmt.Errorf("cannot simulate tx: tx encoder is nil") + } + + tx, err := f.getTx() + if err != nil { + return nil, err + } + return encoder(tx) +} + +// sign signs a given tx with a named key. The bytes signed over are canonical. +// The resulting signature will be added to the transaction builder overwriting the previous +// ones if overwrite=true (otherwise, the signature will be appended). +// Signing a transaction with multiple signers in the DIRECT mode is not supported and will +// return an error. +func (f *Factory) sign(ctx context.Context, overwriteSig bool) (Tx, error) { + if f.keybase == nil { + return nil, errors.New("keybase must be set prior to signing a transaction") + } + + var err error + if f.txParams.signMode == apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED { + f.txParams.signMode = f.txConfig.SignModeHandler().DefaultMode() + } + + pubKey, err := f.keybase.GetPubKey(f.txParams.fromName) + if err != nil { + return nil, err + } + + addr, err := f.ac.BytesToString(pubKey.Address()) + if err != nil { + return nil, err + } + + signerData := signing.SignerData{ + ChainID: f.txParams.chainID, + AccountNumber: f.txParams.accountNumber, + Sequence: f.txParams.sequence, + PubKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(pubKey), + Value: pubKey.Bytes(), + }, + Address: addr, + } + + // For SIGN_MODE_DIRECT, we need to set the SignerInfos before generating + // the sign bytes. This is done by calling setSignatures with a nil + // signature, which in turn calls setSignerInfos internally. + // + // For SIGN_MODE_LEGACY_AMINO, this step is not strictly necessary, + // but we include it for consistency across all sign modes. + // It does not affect the generated sign bytes for LEGACY_AMINO. + // + // By setting the signatures here, we ensure that the correct SignerInfos + // are in place for all subsequent operations, regardless of the sign mode. + sigData := SingleSignatureData{ + SignMode: f.txParams.signMode, + Signature: nil, + } + sig := Signature{ + PubKey: pubKey, + Data: &sigData, + Sequence: f.txParams.sequence, + } + + var prevSignatures []Signature + if !overwriteSig { + tx, err := f.getTx() + if err != nil { + return nil, err + } + + prevSignatures, err = tx.GetSignatures() + if err != nil { + return nil, err + } + } + // Overwrite or append signer infos. + var sigs []Signature + if overwriteSig { + sigs = []Signature{sig} + } else { + sigs = append(sigs, prevSignatures...) + sigs = append(sigs, sig) + } + if err := f.setSignatures(sigs...); err != nil { + return nil, err + } + + tx, err := f.getTx() + if err != nil { + return nil, err + } + + if err := checkMultipleSigners(tx); err != nil { + return nil, err + } + + bytesToSign, err := f.getSignBytesAdapter(ctx, signerData) + if err != nil { + return nil, err + } + + // Sign those bytes + sigBytes, err := f.keybase.Sign(f.txParams.fromName, bytesToSign, f.txParams.signMode) + if err != nil { + return nil, err + } + + // Construct the SignatureV2 struct + sigData = SingleSignatureData{ + SignMode: f.signMode(), + Signature: sigBytes, + } + sig = Signature{ + PubKey: pubKey, + Data: &sigData, + Sequence: f.txParams.sequence, + } + + if overwriteSig { + err = f.setSignatures(sig) + } else { + prevSignatures = append(prevSignatures, sig) + err = f.setSignatures(prevSignatures...) + } + + if err != nil { + return nil, fmt.Errorf("unable to set signatures on payload: %w", err) + } + + return f.getTx() +} + +// getSignBytesAdapter returns the sign bytes for a given transaction and sign mode. +func (f *Factory) getSignBytesAdapter(ctx context.Context, signerData signing.SignerData) ([]byte, error) { + txData, err := f.getSigningTxData() + if err != nil { + return nil, err + } + + // Generate the bytes to be signed. + return f.txConfig.SignModeHandler().GetSignBytes(ctx, f.signMode(), signerData, *txData) +} + +// WithGas returns a copy of the Factory with an updated gas value. +func (f *Factory) WithGas(gas uint64) { + f.txParams.gas = gas +} + +// WithSequence returns a copy of the Factory with an updated sequence number. +func (f *Factory) WithSequence(sequence uint64) { + f.txParams.sequence = sequence +} + +// WithAccountNumber returns a copy of the Factory with an updated account number. +func (f *Factory) WithAccountNumber(accnum uint64) { + f.txParams.accountNumber = accnum +} + +// sequence returns the sequence number. +func (f *Factory) sequence() uint64 { return f.txParams.sequence } + +// gasAdjustment returns the gas adjustment value. +func (f *Factory) gasAdjustment() float64 { return f.txParams.gasAdjustment } + +// simulateAndExecute returns whether to simulate and execute. +func (f *Factory) simulateAndExecute() bool { return f.txParams.simulateAndExecute } + +// signMode returns the sign mode. +func (f *Factory) signMode() apitxsigning.SignMode { return f.txParams.signMode } + +// getSimPK gets the public key to use for building a simulation tx. +// Note, we should only check for keys in the keybase if we are in simulate and execute mode, +// e.g. when using --gas=auto. +// When using --dry-run, we are is simulation mode only and should not check the keybase. +// Ref: https://github.com/cosmos/cosmos-sdk/issues/11283 +func (f *Factory) getSimPK() (cryptotypes.PubKey, error) { + var ( + err error + pk cryptotypes.PubKey = &secp256k1.PubKey{} + ) + + if f.txParams.simulateAndExecute && f.keybase != nil { + pk, err = f.keybase.GetPubKey(f.txParams.fromName) + if err != nil { + return nil, err + } + } else { + // When in dry-run mode, attempt to retrieve the account using the provided address. + // If the account retrieval fails, the default public key is used. + acc, err := f.accountRetriever.GetAccount(context.Background(), f.txParams.address) + if err != nil { + // If there is an error retrieving the account, return the default public key. + return pk, nil + } + // If the account is successfully retrieved, use its public key. + pk = acc.GetPubKey() + } + + return pk, nil +} + +// getSimSignatureData based on the pubKey type gets the correct SignatureData type +// to use for building a simulation tx. +func (f *Factory) getSimSignatureData(pk cryptotypes.PubKey) SignatureData { + multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey) + if !ok { + return &SingleSignatureData{SignMode: f.txParams.signMode} + } + + multiSignatureData := make([]SignatureData, 0, multisigPubKey.Threshold) + for i := uint32(0); i < multisigPubKey.Threshold; i++ { + multiSignatureData = append(multiSignatureData, &SingleSignatureData{ + SignMode: f.signMode(), + }) + } + + return &MultiSignatureData{ + BitArray: &apicrypto.CompactBitArray{}, + Signatures: multiSignatureData, + } +} + +func (f *Factory) getTx() (*wrappedTx, error) { + msgs, err := msgsV1toAnyV2(f.tx.msgs) + if err != nil { + return nil, err + } + + body := &apitx.TxBody{ + Messages: msgs, + Memo: f.tx.memo, + TimeoutHeight: f.tx.timeoutHeight, + TimeoutTimestamp: timestamppb.New(f.tx.timeoutTimestamp), + Unordered: f.tx.unordered, + ExtensionOptions: f.tx.extensionOptions, + NonCriticalExtensionOptions: f.tx.nonCriticalExtensionOptions, + } + + fee, err := f.getFee() + if err != nil { + return nil, err + } + + authInfo := &apitx.AuthInfo{ + SignerInfos: f.tx.signerInfos, + Fee: fee, + } + + bodyBytes, err := marshalOption.Marshal(body) + if err != nil { + return nil, err + } + + authInfoBytes, err := marshalOption.Marshal(authInfo) + if err != nil { + return nil, err + } + + txRawBytes, err := marshalOption.Marshal(&apitx.TxRaw{ + BodyBytes: bodyBytes, + AuthInfoBytes: authInfoBytes, + Signatures: f.tx.signatures, + }) + if err != nil { + return nil, err + } + + decodedTx, err := f.txConfig.Decoder().Decode(txRawBytes) + if err != nil { + return nil, err + } + + return newWrapperTx(f.cdc, decodedTx), nil +} + +// getSigningTxData returns a TxData with the current txState info. +func (f *Factory) getSigningTxData() (*signing.TxData, error) { + tx, err := f.getTx() + if err != nil { + return nil, err + } + + return &signing.TxData{ + Body: tx.Tx.Body, + AuthInfo: tx.Tx.AuthInfo, + BodyBytes: tx.TxRaw.BodyBytes, + AuthInfoBytes: tx.TxRaw.AuthInfoBytes, + BodyHasUnknownNonCriticals: tx.TxBodyHasUnknownNonCriticals, + }, nil +} + +// setSignatures sets the signatures for the transaction builder. +// It takes a variable number of Signature arguments and processes each one to extract the mode information and raw signature. +// It also converts the public key to the appropriate format and sets the signer information. +func (f *Factory) setSignatures(signatures ...Signature) error { + n := len(signatures) + signerInfos := make([]*apitx.SignerInfo, n) + rawSignatures := make([][]byte, n) + + for i, sig := range signatures { + var ( + modeInfo *apitx.ModeInfo + pubKey *codectypes.Any + err error + anyPk *anypb.Any + ) + + modeInfo, rawSignatures[i] = signatureDataToModeInfoAndSig(sig.Data) + if sig.PubKey != nil { + pubKey, err = codectypes.NewAnyWithValue(sig.PubKey) + if err != nil { + return err + } + anyPk = &anypb.Any{ + TypeUrl: pubKey.TypeUrl, + Value: pubKey.Value, + } + } + + signerInfos[i] = &apitx.SignerInfo{ + PublicKey: anyPk, + ModeInfo: modeInfo, + Sequence: sig.Sequence, + } + } + + f.tx.signerInfos = signerInfos + f.tx.signatures = rawSignatures + + return nil +} + +// getFee computes the transaction fee information. +// It returns a pointer to an apitx.Fee struct containing the fee amount, gas limit, payer, and granter information. +// If the granter or payer addresses are set, it converts them from bytes to string using the addressCodec. +func (f *Factory) getFee() (fee *apitx.Fee, err error) { + granterStr := "" + if f.tx.granter != nil { + granterStr, err = f.ac.BytesToString(f.tx.granter) + if err != nil { + return nil, err + } + } + + payerStr := "" + if f.tx.payer != nil { + payerStr, err = f.ac.BytesToString(f.tx.payer) + if err != nil { + return nil, err + } + } + + fee = &apitx.Fee{ + Amount: f.tx.fees, + GasLimit: f.tx.gasLimit, + Payer: payerStr, + Granter: granterStr, + } + + return fee, nil +} + +// setFeePayer sets the fee payer for the transaction. +func (f *Factory) setFeePayer(feePayer string) error { + if feePayer == "" { + return nil + } + + addr, err := f.ac.StringToBytes(feePayer) + if err != nil { + return err + } + f.tx.payer = addr + return nil +} + +// setFeeGranter sets the fee granter's address in the transaction builder. +// If the feeGranter string is empty, the function returns nil without setting an address. +// It converts the feeGranter string to bytes using the address codec and sets it as the granter address. +// Returns an error if the conversion fails. +func (f *Factory) setFeeGranter(feeGranter string) error { + if feeGranter == "" { + return nil + } + + addr, err := f.ac.StringToBytes(feeGranter) + if err != nil { + return err + } + f.tx.granter = addr + + return nil +} + +// msgsV1toAnyV2 converts a slice of transaction.Msg (v1) to a slice of anypb.Any (v2). +// It first converts each transaction.Msg into a codectypes.Any and then converts +// these into anypb.Any. +func msgsV1toAnyV2(msgs []transaction.Msg) ([]*anypb.Any, error) { + anys := make([]*codectypes.Any, len(msgs)) + for i, msg := range msgs { + anyMsg, err := codectypes.NewAnyWithValue(msg) + if err != nil { + return nil, err + } + anys[i] = anyMsg + } + + return intoAnyV2(anys), nil +} + +// intoAnyV2 converts a slice of codectypes.Any (v1) to a slice of anypb.Any (v2). +func intoAnyV2(v1s []*codectypes.Any) []*anypb.Any { + v2s := make([]*anypb.Any, len(v1s)) + for i, v1 := range v1s { + v2s[i] = &anypb.Any{ + TypeUrl: v1.TypeUrl, + Value: v1.Value, + } + } + return v2s +} + +// checkMultipleSigners checks that there can be maximum one DIRECT signer in +// a tx. +func checkMultipleSigners(tx Tx) error { + directSigners := 0 + sigsV2, err := tx.GetSignatures() + if err != nil { + return err + } + for _, sig := range sigsV2 { + directSigners += countDirectSigners(sig.Data) + if directSigners > 1 { + return errors.New("txs signed with CLI can have maximum 1 DIRECT signer") + } + } + + return nil +} + +// validateMemo validates the memo field. +func validateMemo(memo string) error { + // Prevent simple inclusion of a valid mnemonic in the memo field + if memo != "" && bip39.IsMnemonicValid(strings.ToLower(memo)) { + return errors.New("cannot provide a valid mnemonic seed in the memo field") + } + + return nil +} diff --git a/client/v2/tx/factory_test.go b/client/v2/tx/factory_test.go new file mode 100644 index 000000000000..39f21b38d0df --- /dev/null +++ b/client/v2/tx/factory_test.go @@ -0,0 +1,921 @@ +package tx + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/types/known/anypb" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/transaction" + "cosmossdk.io/x/tx/signing" + + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" + "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" + countertypes "github.com/cosmos/cosmos-sdk/testutil/x/counter/types" +) + +var ( + signer = "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9" + addr, _ = ac.StringToBytes(signer) +) + +func TestFactory_prepareTxParams(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + address: addr, + }, + }, + }, + { + name: "without account", + txParams: TxParameters{}, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + var err error + tt.txParams, err = prepareTxParams(tt.txParams, mockAccountRetriever{}, false) + if (err != nil) != tt.error { + t.Errorf("Prepare() error = %v, wantErr %v", err, tt.error) + } + }) + } +} + +func TestFactory_BuildUnsignedTx(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []transaction.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + }, + msgs: []transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: signer, + Count: 0, + }, + }, + }, + { + name: "fees and gas price provided", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + GasConfig: GasConfig{ + gasPrices: []*base.DecCoin{ + { + Amount: "1000", + Denom: "stake", + }, + }, + }, + FeeConfig: FeeConfig{ + fees: []*base.Coin{ + { + Amount: "1000", + Denom: "stake", + }, + }, + }, + }, + msgs: []transaction.Msg{}, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + err = f.BuildUnsignedTx(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Nil(t, f.tx.signatures) + require.Nil(t, f.tx.signerInfos) + } + }) + } +} + +func TestFactory_calculateGas(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []transaction.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + GasConfig: GasConfig{ + gasAdjustment: 1, + }, + }, + msgs: []transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: signer, + Count: 0, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + err = f.calculateGas(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotZero(t, f.txParams.GasConfig) + } + }) + } +} + +func TestFactory_Simulate(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []transaction.Msg + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + GasConfig: GasConfig{ + gasAdjustment: 1, + }, + }, + msgs: []transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: signer, + Count: 0, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + got, got1, err := f.Simulate(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + require.NotZero(t, got1) + } + }) + } +} + +func TestFactory_BuildSimTx(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + msgs []transaction.Msg + want []byte + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + got, err := f.BuildSimTx(tt.msgs...) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + } + }) + } +} + +func TestFactory_Sign(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + wantErr bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + fromName: "alice", + address: addr, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + err = f.BuildUnsignedTx([]transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: signer, + Count: 0, + }, + }...) + require.NoError(t, err) + + require.Nil(t, f.tx.signatures) + require.Nil(t, f.tx.signerInfos) + + tx, err := f.sign(context.Background(), true) + if tt.wantErr { + require.Error(t, err) + } else { + require.NoError(t, err) + sigs, err := tx.GetSignatures() + require.NoError(t, err) + require.NotNil(t, sigs) + require.NotNil(t, f.tx.signerInfos) + } + }) + } +} + +func TestFactory_getSignBytesAdapter(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + error bool + }{ + { + name: "no error", + txParams: TxParameters{ + chainID: "demo", + signMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + AccountConfig: AccountConfig{ + address: addr, + }, + }, + }, + { + name: "signMode not specified", + txParams: TxParameters{ + chainID: "demo", + AccountConfig: AccountConfig{ + address: addr, + }, + }, + error: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + err = f.BuildUnsignedTx([]transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: signer, + Count: 0, + }, + }...) + require.NoError(t, err) + + pk, err := f.keybase.GetPubKey("alice") + require.NoError(t, err) + require.NotNil(t, pk) + + addr, err := f.ac.BytesToString(pk.Address()) + require.NoError(t, err) + require.NotNil(t, addr) + + signerData := signing.SignerData{ + Address: addr, + ChainID: f.txParams.chainID, + AccountNumber: 0, + Sequence: 0, + PubKey: &anypb.Any{ + TypeUrl: codectypes.MsgTypeURL(pk), + Value: pk.Bytes(), + }, + } + + got, err := f.getSignBytesAdapter(context.Background(), signerData) + if tt.error { + require.Error(t, err) + } else { + require.NoError(t, err) + require.NotNil(t, got) + } + }) + } +} + +func Test_validateMemo(t *testing.T) { + tests := []struct { + name string + memo string + wantErr bool + }{ + { + name: "empty memo", + memo: "", + }, + { + name: "valid memo", + memo: "11245", + }, + { + name: "invalid Memo", + memo: "echo echo echo echo echo echo echo echo echo echo echo echo echo echo echo", + wantErr: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if err := validateMemo(tt.memo); (err != nil) != tt.wantErr { + t.Errorf("validateMemo() error = %v, wantErr %v", err, tt.wantErr) + } + }) + } +} + +func TestFactory_WithFunctions(t *testing.T) { + tests := []struct { + name string + txParams TxParameters + withFunc func(*Factory) + checkFunc func(*Factory) bool + }{ + { + name: "with gas", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithGas(1000) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.GasConfig.gas == 1000 + }, + }, + { + name: "with sequence", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithSequence(10) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.AccountConfig.sequence == 10 + }, + }, + { + name: "with account number", + txParams: TxParameters{ + AccountConfig: AccountConfig{ + address: addr, + }, + }, + withFunc: func(f *Factory) { + f.WithAccountNumber(123) + }, + checkFunc: func(f *Factory) bool { + return f.txParams.AccountConfig.accountNumber == 123 + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(setKeyring(), cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, tt.txParams) + require.NoError(t, err) + require.NotNil(t, f) + + tt.withFunc(&f) + require.True(t, tt.checkFunc(&f)) + }) + } +} + +func TestFactory_getTx(t *testing.T) { + tests := []struct { + name string + txSetter func(f *Factory) + checkResult func(Tx) + }{ + { + name: "empty tx", + txSetter: func(f *Factory) { + }, + checkResult: func(tx Tx) { + wTx, ok := tx.(*wrappedTx) + require.True(t, ok) + // require.Equal(t, []*anypb.Any(nil), wTx.Tx.Body.Messages) + require.Nil(t, wTx.Tx.Body.Messages) + require.Empty(t, wTx.Tx.Body.Memo) + require.Equal(t, uint64(0), wTx.Tx.Body.TimeoutHeight) + require.Equal(t, wTx.Tx.Body.Unordered, false) + require.Nil(t, wTx.Tx.Body.ExtensionOptions) + require.Nil(t, wTx.Tx.Body.NonCriticalExtensionOptions) + + require.Nil(t, wTx.Tx.AuthInfo.SignerInfos) + require.Nil(t, wTx.Tx.AuthInfo.Fee.Amount) + require.Equal(t, uint64(0), wTx.Tx.AuthInfo.Fee.GasLimit) + require.Empty(t, wTx.Tx.AuthInfo.Fee.Payer) + require.Empty(t, wTx.Tx.AuthInfo.Fee.Granter) + + require.Nil(t, wTx.Tx.Signatures) + }, + }, + { + name: "full tx", + txSetter: func(f *Factory) { + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := f.ac.BytesToString(pk.Address()) + + f.tx.msgs = []transaction.Msg{&countertypes.MsgIncreaseCounter{ + Signer: addr, + Count: 0, + }} + + err := f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }}...) + require.NoError(t, err) + }, + checkResult: func(tx Tx) { + wTx, ok := tx.(*wrappedTx) + require.True(t, ok) + require.True(t, len(wTx.Tx.Body.Messages) == 1) + + require.NotNil(t, wTx.Tx.AuthInfo.SignerInfos) + require.NotNil(t, wTx.Tx.AuthInfo.Fee.Amount) + + require.NotNil(t, wTx.Tx.Signatures) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + tt.txSetter(&f) + got, err := f.getTx() + require.NoError(t, err) + require.NotNil(t, got) + tt.checkResult(got) + }) + } +} + +func TestFactory_getFee(t *testing.T) { + tests := []struct { + name string + feeAmount []*base.Coin + feeGranter string + feePayer string + }{ + { + name: "get fee with payer", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "", + feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + { + name: "get fee with granter", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + feePayer: "", + }, + { + name: "get fee with granter and granter", + feeAmount: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + feeGranter: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + feePayer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.fees = tt.feeAmount + err = f.setFeeGranter(tt.feeGranter) + require.NoError(t, err) + err = f.setFeePayer(tt.feePayer) + require.NoError(t, err) + + fee, err := f.getFee() + require.NoError(t, err) + require.NotNil(t, fee) + + require.Equal(t, fee.Amount, tt.feeAmount) + require.Equal(t, fee.Granter, tt.feeGranter) + require.Equal(t, fee.Payer, tt.feePayer) + }) + } +} + +func TestFactory_getSigningTxData(t *testing.T) { + tests := []struct { + name string + txSetter func(f *Factory) + }{ + { + name: "empty tx", + txSetter: func(f *Factory) {}, + }, + { + name: "full tx", + txSetter: func(f *Factory) { + pk := secp256k1.GenPrivKey().PubKey() + addr, _ := ac.BytesToString(pk.Address()) + + f.tx.msgs = []transaction.Msg{&countertypes.MsgIncreaseCounter{ + Signer: addr, + Count: 0, + }} + + err := f.setFeePayer(addr) + require.NoError(t, err) + + f.tx.fees = []*base.Coin{{ + Denom: "cosmos", + Amount: "1000", + }} + + err = f.setSignatures([]Signature{{ + PubKey: pk, + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + Sequence: 0, + }}...) + require.NoError(t, err) + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + tt.txSetter(&f) + got, err := f.getSigningTxData() + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func TestFactoryr_setMsgs(t *testing.T) { + tests := []struct { + name string + msgs []transaction.Msg + wantErr bool + }{ + { + name: "set msgs", + msgs: []transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + Count: 0, + }, + &countertypes.MsgIncreaseCounter{ + Signer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + Count: 1, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.msgs = tt.msgs + require.NoError(t, err) + require.Equal(t, len(tt.msgs), len(f.tx.msgs)) + + for i, msg := range tt.msgs { + require.Equal(t, msg, f.tx.msgs[i]) + } + }) + } +} + +func TestFactory_SetMemo(t *testing.T) { + tests := []struct { + name string + memo string + }{ + { + name: "set memo", + memo: "test", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.memo = tt.memo + require.Equal(t, f.tx.memo, tt.memo) + }) + } +} + +func TestFactory_SetFeeAmount(t *testing.T) { + tests := []struct { + name string + coins []*base.Coin + }{ + { + name: "set coins", + coins: []*base.Coin{ + { + Denom: "cosmos", + Amount: "1000", + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.fees = tt.coins + require.Equal(t, len(tt.coins), len(f.tx.fees)) + + for i, coin := range tt.coins { + require.Equal(t, coin.Amount, f.tx.fees[i].Amount) + } + }) + } +} + +func TestFactory_SetGasLimit(t *testing.T) { + tests := []struct { + name string + gasLimit uint64 + }{ + { + name: "set gas limit", + gasLimit: 1, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.gasLimit = tt.gasLimit + require.Equal(t, f.tx.gasLimit, tt.gasLimit) + }) + } +} + +func TestFactory_SetUnordered(t *testing.T) { + tests := []struct { + name string + unordered bool + }{ + { + name: "unordered", + unordered: true, + }, + { + name: "not unordered", + unordered: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + f.tx.unordered = tt.unordered + require.Equal(t, f.tx.unordered, tt.unordered) + }) + } +} + +func TestFactory_setSignatures(t *testing.T) { + tests := []struct { + name string + signatures func() []Signature + }{ + { + name: "set empty single signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: secp256k1.GenPrivKey().PubKey(), + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + Sequence: 0, + }} + }, + }, + { + name: "set single signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: secp256k1.GenPrivKey().PubKey(), + Data: &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + Sequence: 0, + }} + }, + }, + { + name: "set empty multi signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), + Data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: nil, + }, + }, + }, + Sequence: 0, + }} + }, + }, + { + name: "set multi signature", + signatures: func() []Signature { + return []Signature{{ + PubKey: multisig.NewLegacyAminoPubKey(1, []cryptotypes.PubKey{secp256k1.GenPrivKey().PubKey()}), + Data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apitxsigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + Sequence: 0, + }} + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cryptocodec.RegisterInterfaces(cdc.InterfaceRegistry()) + f, err := NewFactory(keybase, cdc, mockAccountRetriever{}, txConf, ac, mockClientConn{}, TxParameters{}) + require.NoError(t, err) + sigs := tt.signatures() + err = f.setSignatures(sigs...) + require.NoError(t, err) + tx, err := f.getTx() + require.NoError(t, err) + signatures, err := tx.GetSignatures() + require.NoError(t, err) + require.Equal(t, len(sigs), len(signatures)) + for i := range signatures { + require.Equal(t, sigs[i].PubKey, signatures[i].PubKey) + } + }) + } +} + +/////////////////////// + +func Test_msgsV1toAnyV2(t *testing.T) { + tests := []struct { + name string + msgs []transaction.Msg + }{ + { + name: "convert msgV1 to V2", + msgs: []transaction.Msg{ + &countertypes.MsgIncreaseCounter{ + Signer: "cosmos1zglwfu6xjzvzagqcmvzewyzjp9xwqw5qwrr8n9", + Count: 0, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := msgsV1toAnyV2(tt.msgs) + require.NoError(t, err) + require.NotNil(t, got) + }) + } +} + +func Test_intoAnyV2(t *testing.T) { + tests := []struct { + name string + msgs []*codectypes.Any + }{ + { + name: "any to v2", + msgs: []*codectypes.Any{ + { + TypeUrl: "/random/msg", + Value: []byte("random message"), + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := intoAnyV2(tt.msgs) + require.NotNil(t, got) + require.Equal(t, len(got), len(tt.msgs)) + for i, msg := range got { + require.Equal(t, msg.TypeUrl, tt.msgs[i].TypeUrl) + require.Equal(t, msg.Value, tt.msgs[i].Value) + } + }) + } +} diff --git a/client/v2/tx/flags.go b/client/v2/tx/flags.go new file mode 100644 index 000000000000..6ef8584042f7 --- /dev/null +++ b/client/v2/tx/flags.go @@ -0,0 +1,52 @@ +package tx + +import ( + "fmt" + "strconv" +) + +// Flag constants for transaction-related flags +const ( + defaultGasLimit = 200000 + gasFlagAuto = "auto" + + flagTimeoutTimestamp = "timeout-timestamp" + flagChainID = "chain-id" + flagNote = "note" + flagSignMode = "sign-mode" + flagAccountNumber = "account-number" + flagSequence = "sequence" + flagFrom = "from" + flagDryRun = "dry-run" + flagGas = "gas" + flagGasAdjustment = "gas-adjustment" + flagGasPrices = "gas-prices" + flagFees = "fees" + flagFeePayer = "fee-payer" + flagFeeGranter = "fee-granter" + flagUnordered = "unordered" + flagOffline = "offline" + flagGenerateOnly = "generate-only" +) + +// parseGasSetting parses a string gas value. The value may either be 'auto', +// which indicates a transaction should be executed in simulate mode to +// automatically find a sufficient gas value, or a string integer. It returns an +// error if a string integer is provided which cannot be parsed. +func parseGasSetting(gasStr string) (bool, uint64, error) { + switch gasStr { + case "": + return false, defaultGasLimit, nil + + case gasFlagAuto: + return true, 0, nil + + default: + gas, err := strconv.ParseUint(gasStr, 10, 64) + if err != nil { + return false, 0, fmt.Errorf("gas must be either integer or %s", gasFlagAuto) + } + + return false, gas, nil + } +} diff --git a/client/v2/tx/signature.go b/client/v2/tx/signature.go new file mode 100644 index 000000000000..66235380072b --- /dev/null +++ b/client/v2/tx/signature.go @@ -0,0 +1,197 @@ +package tx + +import ( + "errors" + "fmt" + + apicrypto "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// Signature holds the necessary components to verify transaction signatures. +type Signature struct { + PubKey cryptotypes.PubKey // Public key for signature verification. + Data SignatureData // Signature data containing the actual signatures. + Sequence uint64 // Account sequence, relevant for SIGN_MODE_DIRECT. +} + +// SignatureData defines an interface for different signature data types. +type SignatureData interface { + isSignatureData() +} + +// SingleSignatureData stores a single signer's signature and its mode. +type SingleSignatureData struct { + SignMode apitxsigning.SignMode // Mode of the signature. + Signature []byte // Actual binary signature. +} + +// MultiSignatureData encapsulates signatures from a multisig transaction. +type MultiSignatureData struct { + BitArray *apicrypto.CompactBitArray // Bitmap of signers. + Signatures []SignatureData // Individual signatures. +} + +func (m *SingleSignatureData) isSignatureData() {} +func (m *MultiSignatureData) isSignatureData() {} + +// signatureDataToModeInfoAndSig converts SignatureData to ModeInfo and its corresponding raw signature. +func signatureDataToModeInfoAndSig(data SignatureData) (*apitx.ModeInfo, []byte) { + if data == nil { + return nil, nil + } + + switch data := data.(type) { + case *SingleSignatureData: + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: data.SignMode}, + }, + }, data.Signature + case *MultiSignatureData: + modeInfos := make([]*apitx.ModeInfo, len(data.Signatures)) + sigs := make([][]byte, len(data.Signatures)) + + for i, d := range data.Signatures { + modeInfos[i], sigs[i] = signatureDataToModeInfoAndSig(d) + } + + multisig := cryptotypes.MultiSignature{Signatures: sigs} + sig, err := multisig.Marshal() + if err != nil { + panic(err) + } + + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: data.BitArray, + ModeInfos: modeInfos, + }, + }, + }, sig + default: + panic(fmt.Sprintf("unexpected signature data type %T", data)) + } +} + +// modeInfoAndSigToSignatureData converts ModeInfo and a raw signature to SignatureData. +func modeInfoAndSigToSignatureData(modeInfo *apitx.ModeInfo, sig []byte) (SignatureData, error) { + switch mi := modeInfo.Sum.(type) { + case *apitx.ModeInfo_Single_: + return &SingleSignatureData{ + SignMode: mi.Single.Mode, + Signature: sig, + }, nil + + case *apitx.ModeInfo_Multi_: + multi := mi.Multi + + sigs, err := decodeMultiSignatures(sig) + if err != nil { + return nil, err + } + + sigsV2 := make([]SignatureData, len(sigs)) + for i, mi := range multi.ModeInfos { + sigsV2[i], err = modeInfoAndSigToSignatureData(mi, sigs[i]) + if err != nil { + return nil, err + } + } + return &MultiSignatureData{ + BitArray: multi.Bitarray, + Signatures: sigsV2, + }, nil + } + + return nil, fmt.Errorf("unsupported ModeInfo type %T", modeInfo) +} + +// decodeMultiSignatures decodes a byte array into individual signatures. +func decodeMultiSignatures(bz []byte) ([][]byte, error) { + multisig := cryptotypes.MultiSignature{} + + err := multisig.Unmarshal(bz) + if err != nil { + return nil, err + } + + if len(multisig.XXX_unrecognized) > 0 { + return nil, errors.New("unrecognized fields in MultiSignature") + } + return multisig.Signatures, nil +} + +// signatureDataToProto converts a SignatureData interface to a protobuf SignatureDescriptor_Data. +// This function supports both SingleSignatureData and MultiSignatureData types. +// For SingleSignatureData, it directly maps the signature mode and signature bytes to the protobuf structure. +// For MultiSignatureData, it recursively converts each signature in the collection to the corresponding protobuf structure. +func signatureDataToProto(data SignatureData) (*apitxsigning.SignatureDescriptor_Data, error) { + switch data := data.(type) { + case *SingleSignatureData: + // Handle single signature data conversion. + return &apitxsigning.SignatureDescriptor_Data{ + Sum: &apitxsigning.SignatureDescriptor_Data_Single_{ + Single: &apitxsigning.SignatureDescriptor_Data_Single{ + Mode: data.SignMode, + Signature: data.Signature, + }, + }, + }, nil + case *MultiSignatureData: + var err error + descDatas := make([]*apitxsigning.SignatureDescriptor_Data, len(data.Signatures)) + + for i, j := range data.Signatures { + descDatas[i], err = signatureDataToProto(j) + if err != nil { + return nil, err + } + } + return &apitxsigning.SignatureDescriptor_Data{ + Sum: &apitxsigning.SignatureDescriptor_Data_Multi_{ + Multi: &apitxsigning.SignatureDescriptor_Data_Multi{ + Bitarray: data.BitArray, + Signatures: descDatas, + }, + }, + }, nil + } + + // Return an error if the data type is not supported. + return nil, fmt.Errorf("unexpected signature data type %T", data) +} + +// SignatureDataFromProto converts a protobuf SignatureDescriptor_Data to a SignatureData interface. +// This function supports both Single and Multi signature data types. +func SignatureDataFromProto(descData *apitxsigning.SignatureDescriptor_Data) (SignatureData, error) { + switch descData := descData.Sum.(type) { + case *apitxsigning.SignatureDescriptor_Data_Single_: + return &SingleSignatureData{ + SignMode: descData.Single.Mode, + Signature: descData.Single.Signature, + }, nil + case *apitxsigning.SignatureDescriptor_Data_Multi_: + var err error + multi := descData.Multi + data := make([]SignatureData, len(multi.Signatures)) + + for i, j := range multi.Signatures { + data[i], err = SignatureDataFromProto(j) + if err != nil { + return nil, err + } + } + + return &MultiSignatureData{ + BitArray: multi.Bitarray, + Signatures: data, + }, nil + } + + return nil, fmt.Errorf("unexpected signature data type %T", descData) +} diff --git a/client/v2/tx/signature_test.go b/client/v2/tx/signature_test.go new file mode 100644 index 000000000000..dd78add38d32 --- /dev/null +++ b/client/v2/tx/signature_test.go @@ -0,0 +1,143 @@ +package tx + +import ( + "reflect" + "testing" + + "github.com/stretchr/testify/require" + + apimultisig "cosmossdk.io/api/cosmos/crypto/multisig/v1beta1" + apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" +) + +func TestSignatureDataToModeInfoAndSig(t *testing.T) { + tests := []struct { + name string + data SignatureData + mIResult *apitx.ModeInfo + sigResult []byte + }{ + { + name: "single signature", + data: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + mIResult: &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + sigResult: []byte("signature"), + }, + { + name: "multi signature", + data: &MultiSignatureData{ + BitArray: nil, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + mIResult: &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: nil, + ModeInfos: []*apitx.ModeInfo{ + { + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + }, + }, + }, + }, + sigResult: []byte("\n\tsignature"), + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + modeInfo, signature := signatureDataToModeInfoAndSig(tt.data) + require.Equal(t, tt.mIResult, modeInfo) + require.Equal(t, tt.sigResult, signature) + }) + } +} + +func TestModeInfoAndSigToSignatureData(t *testing.T) { + type args struct { + modeInfo func() *apitx.ModeInfo + sig []byte + } + tests := []struct { + name string + args args + want SignatureData + wantErr bool + }{ + { + name: "to SingleSignatureData", + args: args{ + modeInfo: func() *apitx.ModeInfo { + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + } + }, + sig: []byte("signature"), + }, + want: &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + { + name: "to MultiSignatureData", + args: args{ + modeInfo: func() *apitx.ModeInfo { + return &apitx.ModeInfo{ + Sum: &apitx.ModeInfo_Multi_{ + Multi: &apitx.ModeInfo_Multi{ + Bitarray: &apimultisig.CompactBitArray{}, + ModeInfos: []*apitx.ModeInfo{ + { + Sum: &apitx.ModeInfo_Single_{ + Single: &apitx.ModeInfo_Single{Mode: apisigning.SignMode_SIGN_MODE_DIRECT}, + }, + }, + }, + }, + }, + } + }, + sig: []byte("\n\tsignature"), + }, + want: &MultiSignatureData{ // Changed from SingleSignatureData to MultiSignatureData + BitArray: &apimultisig.CompactBitArray{}, + Signatures: []SignatureData{ + &SingleSignatureData{ + SignMode: apisigning.SignMode_SIGN_MODE_DIRECT, + Signature: []byte("signature"), + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := modeInfoAndSigToSignatureData(tt.args.modeInfo(), tt.args.sig) + if (err != nil) != tt.wantErr { + t.Errorf("ModeInfoAndSigToSignatureData() error = %v, wantErr %v", err, tt.wantErr) + return + } + if !reflect.DeepEqual(got, tt.want) { + t.Errorf("ModeInfoAndSigToSignatureData() got = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/client/v2/tx/tx.go b/client/v2/tx/tx.go new file mode 100644 index 000000000000..64e0199d8172 --- /dev/null +++ b/client/v2/tx/tx.go @@ -0,0 +1,229 @@ +package tx + +import ( + "bufio" + "errors" + "fmt" + "os" + + "github.com/cosmos/gogoproto/proto" + "github.com/spf13/pflag" + + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/client/v2/internal/account" + "cosmossdk.io/core/transaction" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/input" + "github.com/cosmos/cosmos-sdk/crypto/keyring" +) + +// GenerateOrBroadcastTxCLI will either generate and print an unsigned transaction +// or sign it and broadcast it returning an error upon failure. +func GenerateOrBroadcastTxCLI(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction.Msg) error { + if err := validateMessages(msgs...); err != nil { + return err + } + + txf, err := newFactory(ctx, flagSet) + if err != nil { + return err + } + + genOnly, _ := flagSet.GetBool(flagGenerateOnly) + if genOnly { + return generateOnly(ctx, txf, msgs...) + } + + isDryRun, _ := flagSet.GetBool(flagDryRun) + if isDryRun { + return dryRun(txf, msgs...) + } + + return BroadcastTx(ctx, txf, msgs...) +} + +// newFactory creates a new transaction Factory based on the provided context and flag set. +// It initializes a new CLI keyring, extracts transaction parameters from the flag set, +// configures transaction settings, and sets up an account retriever for the transaction Factory. +func newFactory(ctx client.Context, flagSet *pflag.FlagSet) (Factory, error) { + k, err := keyring.NewAutoCLIKeyring(ctx.Keyring, ctx.AddressCodec) + if err != nil { + return Factory{}, err + } + + txConfig, err := NewTxConfig(ConfigOptions{ + AddressCodec: ctx.AddressCodec, + Cdc: ctx.Codec, + ValidatorAddressCodec: ctx.ValidatorAddressCodec, + EnablesSignModes: ctx.TxConfig.SignModeHandler().SupportedModes(), + }) + if err != nil { + return Factory{}, err + } + + accRetriever := account.NewAccountRetriever(ctx.AddressCodec, ctx, ctx.InterfaceRegistry) + + txf, err := NewFactoryFromFlagSet(flagSet, k, ctx.Codec, accRetriever, txConfig, ctx.AddressCodec, ctx) + if err != nil { + return Factory{}, err + } + + return txf, nil +} + +// validateMessages validates all msgs before generating or broadcasting the tx. +// We were calling ValidateBasic separately in each CLI handler before. +// Right now, we're factorizing that call inside this function. +// ref: https://github.com/cosmos/cosmos-sdk/pull/9236#discussion_r623803504 +func validateMessages(msgs ...transaction.Msg) error { + for _, msg := range msgs { + m, ok := msg.(HasValidateBasic) + if !ok { + continue + } + + if err := m.ValidateBasic(); err != nil { + return err + } + } + + return nil +} + +// generateOnly prepares the transaction and prints the unsigned transaction string. +// It first calls Prepare on the transaction factory to set up any necessary pre-conditions. +// If preparation is successful, it generates an unsigned transaction string using the provided messages. +func generateOnly(ctx client.Context, txf Factory, msgs ...transaction.Msg) error { + uTx, err := txf.UnsignedTxString(msgs...) + if err != nil { + return err + } + + return ctx.PrintString(uTx) +} + +// dryRun performs a dry run of the transaction to estimate the gas required. +// It prepares the transaction factory and simulates the transaction with the provided messages. +func dryRun(txf Factory, msgs ...transaction.Msg) error { + _, gas, err := txf.Simulate(msgs...) + if err != nil { + return err + } + + _, err = fmt.Fprintf(os.Stderr, "%s\n", GasEstimateResponse{GasEstimate: gas}) + return err +} + +// SimulateTx simulates a tx and returns the simulation response obtained by the query. +func SimulateTx(ctx client.Context, flagSet *pflag.FlagSet, msgs ...transaction.Msg) (proto.Message, error) { + txf, err := newFactory(ctx, flagSet) + if err != nil { + return nil, err + } + + simulation, _, err := txf.Simulate(msgs...) + return simulation, err +} + +// BroadcastTx attempts to generate, sign and broadcast a transaction with the +// given set of messages. It will also simulate gas requirements if necessary. +// It will return an error upon failure. +func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...transaction.Msg) error { + if txf.simulateAndExecute() { + err := txf.calculateGas(msgs...) + if err != nil { + return err + } + } + + err := txf.BuildUnsignedTx(msgs...) + if err != nil { + return err + } + + if !clientCtx.SkipConfirm { + encoder := txf.txConfig.TxJSONEncoder() + if encoder == nil { + return errors.New("failed to encode transaction: tx json encoder is nil") + } + + unsigTx, err := txf.getTx() + if err != nil { + return err + } + txBytes, err := encoder(unsigTx) + if err != nil { + return fmt.Errorf("failed to encode transaction: %w", err) + } + + if err := clientCtx.PrintRaw(txBytes); err != nil { + _, _ = fmt.Fprintf(os.Stderr, "error: %v\n%s\n", err, txBytes) + } + + buf := bufio.NewReader(os.Stdin) + ok, err := input.GetConfirmation("confirm transaction before signing and broadcasting", buf, os.Stderr) + if err != nil { + _, _ = fmt.Fprintf(os.Stderr, "error: %v\ncanceled transaction\n", err) + return err + } + if !ok { + _, _ = fmt.Fprintln(os.Stderr, "canceled transaction") + return nil + } + } + + signedTx, err := txf.sign(clientCtx.CmdContext, true) + if err != nil { + return err + } + + txBytes, err := txf.txConfig.TxEncoder()(signedTx) + if err != nil { + return err + } + + // broadcast to a CometBFT node + res, err := clientCtx.BroadcastTx(txBytes) + if err != nil { + return err + } + + return clientCtx.PrintProto(res) +} + +// countDirectSigners counts the number of DIRECT signers in a signature data. +func countDirectSigners(sigData SignatureData) int { + switch data := sigData.(type) { + case *SingleSignatureData: + if data.SignMode == apitxsigning.SignMode_SIGN_MODE_DIRECT { + return 1 + } + + return 0 + case *MultiSignatureData: + directSigners := 0 + for _, d := range data.Signatures { + directSigners += countDirectSigners(d) + } + + return directSigners + default: + panic("unreachable case") + } +} + +// getSignMode returns the corresponding apitxsigning.SignMode based on the provided mode string. +func getSignMode(mode string) apitxsigning.SignMode { + switch mode { + case "direct": + return apitxsigning.SignMode_SIGN_MODE_DIRECT + case "direct-aux": + return apitxsigning.SignMode_SIGN_MODE_DIRECT_AUX + case "amino-json": + return apitxsigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON + case "textual": + return apitxsigning.SignMode_SIGN_MODE_TEXTUAL + } + return apitxsigning.SignMode_SIGN_MODE_UNSPECIFIED +} diff --git a/client/v2/tx/types.go b/client/v2/tx/types.go new file mode 100644 index 000000000000..ee60c27065b6 --- /dev/null +++ b/client/v2/tx/types.go @@ -0,0 +1,214 @@ +package tx + +import ( + "fmt" + "time" + + "github.com/spf13/pflag" + "google.golang.org/protobuf/types/known/anypb" + + base "cosmossdk.io/api/cosmos/base/v1beta1" + apitxsigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + apitx "cosmossdk.io/api/cosmos/tx/v1beta1" + keyring2 "cosmossdk.io/client/v2/autocli/keyring" + "cosmossdk.io/client/v2/internal/coins" + "cosmossdk.io/core/address" + "cosmossdk.io/core/transaction" + + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +// HasValidateBasic is a copy of types.HasValidateBasic to avoid sdk import. +type HasValidateBasic interface { + // ValidateBasic does a simple validation check that + // doesn't require access to any other information. + ValidateBasic() error +} + +// TxParameters defines the parameters required for constructing a transaction. +type TxParameters struct { + timeoutTimestamp time.Time // timeoutTimestamp indicates a timestamp after which the transaction is no longer valid. + chainID string // chainID specifies the unique identifier of the blockchain where the transaction will be processed. + memo string // memo contains any arbitrary memo to be attached to the transaction. + signMode apitxsigning.SignMode // signMode determines the signing mode to be used for the transaction. + + AccountConfig // AccountConfig includes information about the transaction originator's account. + GasConfig // GasConfig specifies the gas settings for the transaction. + FeeConfig // FeeConfig details the fee associated with the transaction. + ExecutionOptions // ExecutionOptions includes settings that modify how the transaction is executed. +} + +// AccountConfig defines the 'account' related fields in a transaction. +type AccountConfig struct { + // accountNumber is the unique identifier for the account. + accountNumber uint64 + // sequence is the sequence number of the transaction. + sequence uint64 + // fromName is the name of the account sending the transaction. + fromName string + // fromAddress is the address of the account sending the transaction. + fromAddress string + // address is the byte representation of the account address. + address []byte +} + +// GasConfig defines the 'gas' related fields in a transaction. +// GasConfig defines the gas-related settings for a transaction. +type GasConfig struct { + gas uint64 // gas is the amount of gas requested for the transaction. + gasAdjustment float64 // gasAdjustment is the factor by which the estimated gas is multiplied to calculate the final gas limit. + gasPrices []*base.DecCoin // gasPrices is a list of denominations of DecCoin used to calculate the fee paid for the gas. +} + +// NewGasConfig creates a new GasConfig with the specified gas, gasAdjustment, and gasPrices. +// If the provided gas value is zero, it defaults to a predefined value (defaultGas). +// The gasPrices string is parsed into a slice of DecCoin. +func NewGasConfig(gas uint64, gasAdjustment float64, gasPrices string) (GasConfig, error) { + parsedGasPrices, err := coins.ParseDecCoins(gasPrices) + if err != nil { + return GasConfig{}, err + } + + return GasConfig{ + gas: gas, + gasAdjustment: gasAdjustment, + gasPrices: parsedGasPrices, + }, nil +} + +// FeeConfig holds the fee details for a transaction. +type FeeConfig struct { + fees []*base.Coin // fees are the amounts paid for the transaction. + feePayer string // feePayer is the account responsible for paying the fees. + feeGranter string // feeGranter is the account granting the fee payment if different from the payer. +} + +// NewFeeConfig creates a new FeeConfig with the specified fees, feePayer, and feeGranter. +// It parses the fees string into a slice of Coin, handling normalization. +func NewFeeConfig(fees, feePayer, feeGranter string) (FeeConfig, error) { + parsedFees, err := coins.ParseCoinsNormalized(fees) + if err != nil { + return FeeConfig{}, err + } + + return FeeConfig{ + fees: parsedFees, + feePayer: feePayer, + feeGranter: feeGranter, + }, nil +} + +// ExecutionOptions defines the transaction execution options ran by the client +type ExecutionOptions struct { + unordered bool // unordered indicates if the transaction execution order is not guaranteed. + simulateAndExecute bool // simulateAndExecute indicates if the transaction should be simulated before execution. +} + +// GasEstimateResponse defines a response definition for tx gas estimation. +type GasEstimateResponse struct { + GasEstimate uint64 `json:"gas_estimate" yaml:"gas_estimate"` +} + +func (gr GasEstimateResponse) String() string { + return fmt.Sprintf("gas estimate: %d", gr.GasEstimate) +} + +// txState represents the internal state of a transaction. +type txState struct { + msgs []transaction.Msg + timeoutHeight uint64 + timeoutTimestamp time.Time + granter []byte + payer []byte + unordered bool + memo string + gasLimit uint64 + fees []*base.Coin + signerInfos []*apitx.SignerInfo + signatures [][]byte + + extensionOptions []*anypb.Any + nonCriticalExtensionOptions []*anypb.Any +} + +// Tx defines the interface for transaction operations. +type Tx interface { + transaction.Tx + + // GetSigners fetches the addresses of the signers of the transaction. + GetSigners() ([][]byte, error) + // GetPubKeys retrieves the public keys of the signers of the transaction. + GetPubKeys() ([]cryptotypes.PubKey, error) + // GetSignatures fetches the signatures attached to the transaction. + GetSignatures() ([]Signature, error) +} + +// txParamsFromFlagSet extracts the transaction parameters from the provided FlagSet. +func txParamsFromFlagSet(flags *pflag.FlagSet, keybase keyring2.Keyring, ac address.Codec) (params TxParameters, err error) { + timestampUnix, _ := flags.GetInt64(flagTimeoutTimestamp) + timeoutTimestamp := time.Unix(timestampUnix, 0) + chainID, _ := flags.GetString(flagChainID) + memo, _ := flags.GetString(flagNote) + signMode, _ := flags.GetString(flagSignMode) + + accNumber, _ := flags.GetUint64(flagAccountNumber) + sequence, _ := flags.GetUint64(flagSequence) + from, _ := flags.GetString(flagFrom) + + var fromName, fromAddress string + var addr []byte + isDryRun, _ := flags.GetBool(flagDryRun) + if isDryRun { + addr, err = ac.StringToBytes(from) + } else { + fromName, fromAddress, _, err = keybase.KeyInfo(from) + if err == nil { + addr, err = ac.StringToBytes(fromAddress) + } + } + if err != nil { + return params, err + } + + gas, _ := flags.GetString(flagGas) + simulate, gasValue, _ := parseGasSetting(gas) + gasAdjustment, _ := flags.GetFloat64(flagGasAdjustment) + gasPrices, _ := flags.GetString(flagGasPrices) + + fees, _ := flags.GetString(flagFees) + feePayer, _ := flags.GetString(flagFeePayer) + feeGrater, _ := flags.GetString(flagFeeGranter) + + unordered, _ := flags.GetBool(flagUnordered) + + gasConfig, err := NewGasConfig(gasValue, gasAdjustment, gasPrices) + if err != nil { + return params, err + } + feeConfig, err := NewFeeConfig(fees, feePayer, feeGrater) + if err != nil { + return params, err + } + + txParams := TxParameters{ + timeoutTimestamp: timeoutTimestamp, + chainID: chainID, + memo: memo, + signMode: getSignMode(signMode), + AccountConfig: AccountConfig{ + accountNumber: accNumber, + sequence: sequence, + fromName: fromName, + fromAddress: fromAddress, + address: addr, + }, + GasConfig: gasConfig, + FeeConfig: feeConfig, + ExecutionOptions: ExecutionOptions{ + unordered: unordered, + simulateAndExecute: simulate, + }, + } + + return txParams, nil +} diff --git a/client/v2/tx/wrapper.go b/client/v2/tx/wrapper.go new file mode 100644 index 000000000000..fbcf62126bfc --- /dev/null +++ b/client/v2/tx/wrapper.go @@ -0,0 +1,115 @@ +package tx + +import ( + "fmt" + "reflect" + "strings" + + "github.com/cosmos/gogoproto/proto" + "google.golang.org/protobuf/types/known/anypb" + + "cosmossdk.io/core/transaction" + "cosmossdk.io/x/tx/decode" + + "github.com/cosmos/cosmos-sdk/codec" + cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" +) + +var ( + _ transaction.Tx = wrappedTx{} + _ Tx = wrappedTx{} +) + +// wrappedTx wraps a transaction and provides a codec for binary encoding/decoding. +type wrappedTx struct { + *decode.DecodedTx + + cdc codec.BinaryCodec +} + +func newWrapperTx(cdc codec.BinaryCodec, decodedTx *decode.DecodedTx) *wrappedTx { + return &wrappedTx{ + DecodedTx: decodedTx, + cdc: cdc, + } +} + +// GetSigners fetches the addresses of the signers of the transaction. +func (w wrappedTx) GetSigners() ([][]byte, error) { + return w.Signers, nil +} + +// GetPubKeys retrieves the public keys of the signers from the transaction's SignerInfos. +func (w wrappedTx) GetPubKeys() ([]cryptotypes.PubKey, error) { + signerInfos := w.Tx.AuthInfo.SignerInfos + pks := make([]cryptotypes.PubKey, len(signerInfos)) + + for i, si := range signerInfos { + // NOTE: it is okay to leave this nil if there is no PubKey in the SignerInfo. + // PubKey's can be left unset in SignerInfo. + if si.PublicKey == nil { + continue + } + maybePk, err := w.decodeAny(si.PublicKey) + if err != nil { + return nil, err + } + pk, ok := maybePk.(cryptotypes.PubKey) + if !ok { + return nil, fmt.Errorf("invalid public key type: %T", maybePk) + } + pks[i] = pk + } + + return pks, nil +} + +// GetSignatures fetches the signatures attached to the transaction. +func (w wrappedTx) GetSignatures() ([]Signature, error) { + signerInfos := w.Tx.AuthInfo.SignerInfos + sigs := w.Tx.Signatures + + pubKeys, err := w.GetPubKeys() + if err != nil { + return nil, err + } + signatures := make([]Signature, len(sigs)) + + for i, si := range signerInfos { + if si.ModeInfo == nil || si.ModeInfo.Sum == nil { + signatures[i] = Signature{ + PubKey: pubKeys[i], + } + } else { + sigData, err := modeInfoAndSigToSignatureData(si.ModeInfo, sigs[i]) + if err != nil { + return nil, err + } + signatures[i] = Signature{ + PubKey: pubKeys[i], + Data: sigData, + Sequence: si.GetSequence(), + } + } + } + + return signatures, nil +} + +// decodeAny decodes a protobuf Any message into a concrete proto.Message. +func (w wrappedTx) decodeAny(anyPb *anypb.Any) (proto.Message, error) { + name := anyPb.GetTypeUrl() + if i := strings.LastIndexByte(name, '/'); i >= 0 { + name = name[i+len("/"):] + } + typ := proto.MessageType(name) + if typ == nil { + return nil, fmt.Errorf("unknown type: %s", name) + } + v1 := reflect.New(typ.Elem()).Interface().(proto.Message) + err := w.cdc.Unmarshal(anyPb.GetValue(), v1) + if err != nil { + return nil, err + } + return v1, nil +} diff --git a/collections/go.mod b/collections/go.mod index 5a491c211e23..e1d9dcef95d1 100644 --- a/collections/go.mod +++ b/collections/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/collections go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.3 + cosmossdk.io/core v1.0.0-alpha.4 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/schema v0.3.0 github.com/stretchr/testify v1.9.0 diff --git a/collections/go.sum b/collections/go.sum index 5978e5595551..ad552827598c 100644 --- a/collections/go.sum +++ b/collections/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= -cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= +cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= diff --git a/core/testing/go.mod b/core/testing/go.mod index 8c20811c6c90..95f3b6a38c59 100644 --- a/core/testing/go.mod +++ b/core/testing/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/core/testing go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.3 + cosmossdk.io/core v1.0.0-alpha.4 github.com/golang/mock v1.6.0 github.com/tidwall/btree v1.7.0 ) diff --git a/core/testing/go.sum b/core/testing/go.sum index d1db25cac6fa..9fc6d98fad48 100644 --- a/core/testing/go.sum +++ b/core/testing/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= -cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= +cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= diff --git a/crypto/README.md b/crypto/README.md new file mode 100644 index 000000000000..269d840c6e80 --- /dev/null +++ b/crypto/README.md @@ -0,0 +1,53 @@ +# Crypto + +The `crypto` directory contains the components responsible for handling cryptographic operations, key management, and secure interactions with hardware wallets. + +## Components + +### Keyring + +Keyring is the primary interface for managing cryptographic keys. It provides a unified API to create, store, retrieve, and manage keys securely across different storage backends. + +#### Supported Backends + +* **OS**: Uses the operating system's default credential store. +* **File**: Stores encrypted keyring in the application's configuration directory. +* **KWallet**: Integrates with KDE Wallet Manager. +* **Pass**: Leverages the `pass` command-line utility. +* **Keyctl**: Uses Linux's kernel security key management system. +* **Test**: Stores (insecurely) keys to disk for testing purposes. +* **Memory**: Provides transient storage where keys are discarded when the process terminates. + +### Codec + +The Codec component handles serialization and deserialization of cryptographic structures in the crypto package. It ensures proper encoding of keys, signatures, and other artifacts for storage and transmission. The Codec also manages conversion between CometBFT and SDK key formats. + +### Ledger Integration + +Support for Ledger hardware wallets is integrated to provide enhanced security for key management and signing operations. The Ledger integration supports SECP256K1 keys and offers various features: + +#### Key Features + +* **Public Key Retrieval**: Supports both safe (with user verification) and unsafe (without user verification) methods to retrieve public keys from the Ledger device. +* **Address Generation**: Can generate and display Bech32 addresses on the Ledger device for user verification. +* **Transaction Signing**: Allows signing of transactions with user confirmation on the Ledger device. +* **Multiple HD Path Support**: Supports various BIP44 derivation paths for key generation and management. +* **Customizable Options**: Provides options to customize Ledger usage, including app name, public key creation, and DER to BER signature conversion. + +#### Implementation Details + +* The integration is built to work with or without CGO. +* It includes a mock implementation for testing purposes, which can be enabled with the `test_ledger_mock` build tag. +* The real Ledger device interaction is implemented when the `ledger` build tag is used. +* The integration supports both SIGN_MODE_LEGACY_AMINO_JSON and SIGN_MODE_TEXTUAL signing modes. + +#### Usage Considerations + +* Ledger support requires the appropriate Cosmos app to be installed and opened on the Ledger device. +* The integration includes safeguards to prevent key overwriting and ensures that the correct device and app are being used. + +#### Security Notes + +* The integration includes methods to validate keys and addresses with user confirmation on the Ledger device. +* It's recommended to use the safe methods that require user verification for critical operations like key generation and address display. +* The mock implementation should only be used for testing and development purposes, not in production environments. \ No newline at end of file diff --git a/crypto/keyring/autocli.go b/crypto/keyring/autocli.go index 0dd91ff60a43..26f39b3e4362 100644 --- a/crypto/keyring/autocli.go +++ b/crypto/keyring/autocli.go @@ -2,6 +2,7 @@ package keyring import ( signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1" + "cosmossdk.io/core/address" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" @@ -21,15 +22,22 @@ type autoCLIKeyring interface { // Sign signs the given bytes with the key with the given name. Sign(name string, msg []byte, signMode signingv1beta1.SignMode) ([]byte, error) + + // KeyType returns the type of the key. + KeyType(name string) (uint, error) + + // KeyInfo given a key name or address returns key name, key address and key type. + KeyInfo(name string) (string, string, uint, error) } // NewAutoCLIKeyring wraps the SDK keyring and make it compatible with the AutoCLI keyring interfaces. -func NewAutoCLIKeyring(kr Keyring) (autoCLIKeyring, error) { - return &autoCLIKeyringAdapter{kr}, nil +func NewAutoCLIKeyring(kr Keyring, ac address.Codec) (autoCLIKeyring, error) { + return &autoCLIKeyringAdapter{kr, ac}, nil } type autoCLIKeyringAdapter struct { Keyring + ac address.Codec } func (a *autoCLIKeyringAdapter) List() ([]string, error) { @@ -84,3 +92,40 @@ func (a *autoCLIKeyringAdapter) Sign(name string, msg []byte, signMode signingv1 signBytes, _, err := a.Keyring.Sign(record.Name, msg, sdkSignMode) return signBytes, err } + +func (a *autoCLIKeyringAdapter) KeyType(name string) (uint, error) { + record, err := a.Keyring.Key(name) + if err != nil { + return 0, err + } + + return uint(record.GetType()), nil +} + +func (a *autoCLIKeyringAdapter) KeyInfo(nameOrAddr string) (string, string, uint, error) { + addr, err := a.ac.StringToBytes(nameOrAddr) + if err != nil { + // If conversion fails, it's likely a name, not an address + record, err := a.Keyring.Key(nameOrAddr) + if err != nil { + return "", "", 0, err + } + addr, err = record.GetAddress() + if err != nil { + return "", "", 0, err + } + addrStr, err := a.ac.BytesToString(addr) + if err != nil { + return "", "", 0, err + } + return record.Name, addrStr, uint(record.GetType()), nil + } + + // If conversion succeeds, it's an address, get the key info by address + record, err := a.Keyring.KeyByAddress(addr) + if err != nil { + return "", "", 0, err + } + + return record.Name, nameOrAddr, uint(record.GetType()), nil +} diff --git a/crypto/ledger/ledger_secp256k1.go b/crypto/ledger/ledger_secp256k1.go index 67dcc73981ab..3449d0bfd1b1 100644 --- a/crypto/ledger/ledger_secp256k1.go +++ b/crypto/ledger/ledger_secp256k1.go @@ -341,6 +341,12 @@ func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (types.PubKey, error func getPubKeyAddrSafe(device SECP256K1, path hd.BIP44Params, hrp string) (types.PubKey, string, error) { publicKey, addr, err := device.GetAddressPubKeySECP256K1(path.DerivationPath(), hrp) if err != nil { + // Check special case if user is trying to use an index > 100 + if path.AddressIndex > 100 { + return nil, "", fmt.Errorf("%w: cannot derive paths where index > 100: %s "+ + "This is a security measure to avoid very hard to find derivation paths introduced by a possible attacker. "+ + "You can disable this by setting expert mode in your ledger device. Do this at your own risk", err, path) + } return nil, "", fmt.Errorf("%w: address rejected for path %s", err, path) } diff --git a/docs/architecture/PROCESS.md b/docs/architecture/PROCESS.md index bca4cdf51b15..15e11639c409 100644 --- a/docs/architecture/PROCESS.md +++ b/docs/architecture/PROCESS.md @@ -1,8 +1,8 @@ # ADR Creation Process 1. Copy the `adr-template.md` file. Use the following filename pattern: `adr-next_number-title.md` -2. Create a draft Pull Request if you want to get an early feedback. -3. Make sure the context and solution is clear and well documented. +2. Create a draft Pull Request if you want to get early feedback. +3. Make sure the context and solution are clear and well documented. 4. Add an entry to a list in the [README](./README.md) file. 5. Create a Pull Request to propose a new ADR. @@ -14,7 +14,7 @@ An ADR is a document to document an implementation and design that may or may no ADR creation is an **iterative** process. Instead of having a high amount of communication overhead, an ADR is used when there is already a decision made and implementation details need to be added. The ADR should document what the collective consensus for the specific issue is and how to solve it. -1. Every ADR should start with either an RFC or discussion where consensus has been met. +1. Every ADR should start with either an RFC or a discussion where consensus has been met. 2. Once consensus is met, a GitHub Pull Request (PR) is created with a new document based on the `adr-template.md`. @@ -44,9 +44,9 @@ DRAFT -> PROPOSED -> LAST CALL yyyy-mm-dd -> ACCEPTED | REJECTED -> SUPERSEDED b ABANDONED ``` -* `DRAFT`: [optional] an ADR which is work in progress, not being ready for a general review. This is to present an early work and get an early feedback in a Draft Pull Request form. -* `PROPOSED`: an ADR covering a full solution architecture and still in the review - project stakeholders haven't reached an agreed yet. -* `LAST CALL `: [optional] clear notify that we are close to accept updates. Changing a status to `LAST CALL` means that social consensus (of Cosmos SDK maintainers) has been reached and we still want to give it a time to let the community react or analyze. +* `DRAFT`: [optional] an ADR which is a work in progress, not being ready for a general review. This is to present an early work and get early feedback in a Draft Pull Request form. +* `PROPOSED`: an ADR covering a full solution architecture and still in the review - project stakeholders haven't reached an agreement yet. +* `LAST CALL `: [optional] Notify that we are close to accepting updates. Changing a status to `LAST CALL` means that social consensus (of Cosmos SDK maintainers) has been reached and we still want to give it a time to let the community react or analyze. * `ACCEPTED`: ADR which will represent a currently implemented or to be implemented architecture design. * `REJECTED`: ADR can go from PROPOSED or ACCEPTED to rejected if the consensus among project stakeholders will decide so. * `SUPERSEDED by ADR-xxx`: ADR which has been superseded by a new ADR. diff --git a/docs/architecture/adr-002-docs-structure.md b/docs/architecture/adr-002-docs-structure.md index 5819151fc1dc..aea7d60e8638 100644 --- a/docs/architecture/adr-002-docs-structure.md +++ b/docs/architecture/adr-002-docs-structure.md @@ -40,7 +40,7 @@ docs/ The files in each sub-folders do not matter and will likely change. What matters is the sectioning: * `README`: Landing page of the docs. -* `intro`: Introductory material. Goal is to have a short explainer of the Cosmos SDK and then channel people to the resource they need. The [Cosmos SDK tutorial](https://github.com/cosmos/sdk-application-tutorial/) will be highlighted, as well as the `godocs`. +* `intro`: Introductory material. Goal is to have a short explainer of the Cosmos SDK and then channel people to the resources they need. The [Cosmos SDK tutorial](https://github.com/cosmos/sdk-application-tutorial/) will be highlighted, as well as the `godocs`. * `concepts`: Contains high-level explanations of the abstractions of the Cosmos SDK. It does not contain specific code implementation and does not need to be updated often. **It is not an API specification of the interfaces**. API spec is the `godoc`. * `clients`: Contains specs and info about the various Cosmos SDK clients. * `spec`: Contains specs of modules, and others. @@ -69,7 +69,7 @@ Accepted * The `/docs` folder now only contains Cosmos SDK and gaia related material. Later, it will only contain Cosmos SDK related material. * Developers only have to update `/docs` folder when they open a PR (and not `/examples` for example). * Easier for developers to find what they need to update in the docs thanks to reworked architecture. -* Cleaner vuepress build for website docs. +* Cleaner `vuepress` build for website docs. * Will help build an executable doc (cf https://github.com/cosmos/cosmos-sdk/issues/2611) ### Neutral diff --git a/docs/architecture/adr-043-nft-module.md b/docs/architecture/adr-043-nft-module.md index 5968eb1305aa..40c21cd3c6d9 100644 --- a/docs/architecture/adr-043-nft-module.md +++ b/docs/architecture/adr-043-nft-module.md @@ -17,9 +17,9 @@ This ADR defines the `x/nft` module which is a generic implementation of NFTs, r * `MsgNewClass` - Receive the user's request to create a class, and call the `NewClass` of the `x/nft` module. * `MsgUpdateClass` - Receive the user's request to update a class, and call the `UpdateClass` of the `x/nft` module. -* `MsgMintNFT` - Receive the user's request to mint a nft, and call the `MintNFT` of the `x/nft` module. -* `BurnNFT` - Receive the user's request to burn a nft, and call the `BurnNFT` of the `x/nft` module. -* `UpdateNFT` - Receive the user's request to update a nft, and call the `UpdateNFT` of the `x/nft` module. +* `MsgMintNFT` - Receive the user's request to mint an NFT, and call the `MintNFT` of the `x/nft` module. +* `BurnNFT` - Receive the user's request to burn an NFT, and call the `BurnNFT` of the `x/nft` module. +* `UpdateNFT` - Receive the user's request to update an NFT, and call the `UpdateNFT` of the `x/nft` module. ## Context @@ -48,7 +48,7 @@ We create a `x/nft` module, which contains the following functionality: * Expose external `Message` interface for users to transfer ownership of their NFTs. * Query NFTs and their supply information. -The proposed module is a base module for NFT app logic. It's goal it to provide a common layer for storage, basic transfer functionality and IBC. The module should not be used as a standalone. +The proposed module is a base module for NFT app logic. Its goal is to provide a common layer for storage, basic transfer functionality and IBC. The module should not be used as a standalone. Instead an app should create a specialized module to handle app specific logic (eg: NFT ID construction, royalty), user level minting and burning. Moreover an app specialized module should handle auxiliary data to support the app logic (eg indexes, ORM, business data). All data carried over IBC must be part of the `NFT` or `Class` type described below. The app specific NFT data should be encoded in `NFT.data` for cross-chain integrity. Other objects related to NFT, which are not important for integrity can be part of the app specific module. @@ -58,7 +58,7 @@ All data carried over IBC must be part of the `NFT` or `Class` type described be We propose two main types: * `Class` -- describes NFT class. We can think about it as a smart contract address. -* `NFT` -- object representing unique, non fungible asset. Each NFT is associated with a Class. +* `NFT` -- object representing unique, non-fungible asset. Each NFT is associated with a class. #### Class @@ -81,7 +81,7 @@ message Class { * `symbol` is the symbol usually shown on exchanges for the NFT class; _optional_ * `description` is a detailed description of the NFT class; _optional_ * `uri` is a URI for the class metadata stored off chain. It should be a JSON file that contains metadata about the NFT class and NFT data schema ([OpenSea example](https://docs.opensea.io/docs/contract-level-metadata)); _optional_ -* `uri_hash` is a hash of the document pointed by uri; _optional_ +* `uri_hash` is a hash of the document pointed by URI; _optional_ * `data` is app specific metadata of the class; _optional_ #### NFT @@ -107,7 +107,7 @@ message NFT { * `uri` is a URI for the NFT metadata stored off chain. Should point to a JSON file that contains metadata about this NFT (Ref: [ERC721 standard and OpenSea extension](https://docs.opensea.io/docs/metadata-standards)); _required_ * `uri_hash` is a hash of the document pointed by uri; _optional_ -* `data` is an app specific data of the NFT. CAN be used by composing modules to specify additional properties of the NFT; _optional_ +* `data` is an app specific data of the NFT. Can be used by composing modules to specify additional properties of the NFT; _optional_ This ADR doesn't specify values that `data` can take; however, best practices recommend upper-level NFT modules clearly specify their contents. Although the value of this field doesn't provide the additional context required to manage NFT records, which means that the field can technically be removed from the specification, the field's existence allows basic informational/UI functionality. diff --git a/docs/architecture/adr-069-gov-improvements.md b/docs/architecture/adr-069-gov-improvements.md index af5b12645205..1ef6971c713d 100644 --- a/docs/architecture/adr-069-gov-improvements.md +++ b/docs/architecture/adr-069-gov-improvements.md @@ -6,7 +6,7 @@ ## Status -ACCEPTED +ACCEPTED - Implemented ## Abstract diff --git a/docs/build/abci/00-introduction.md b/docs/build/abci/00-introduction.md index 6b7cd8ec3c89..7d955d41d956 100644 --- a/docs/build/abci/00-introduction.md +++ b/docs/build/abci/00-introduction.md @@ -19,7 +19,7 @@ The 5 methods introduced during ABCI 2.0 (compared to ABCI v0) are: Based on validator voting power, CometBFT chooses a block proposer and calls `PrepareProposal` on the block proposer's application (Cosmos SDK). The selected block proposer is responsible for collecting outstanding transactions from the mempool, adhering to the application's specifications. The application can enforce custom transaction ordering and incorporate additional transactions, potentially generated from vote extensions in the previous block. -To perform this manipulation on the application side, a custom handler must be implemented. By default, the Cosmos SDK provides `PrepareProposalHandler`, used in conjunction with an application specific mempool. A custom handler can be written by application developer, if a noop handler provided, all transactions are considered valid. Please see [this](https://github.com/fatal-fruit/abci-workshop) tutorial for more information on custom handlers. +To perform this manipulation on the application side, a custom handler must be implemented. By default, the Cosmos SDK provides `PrepareProposalHandler`, used in conjunction with an application specific mempool. A custom handler can be written by application developer, if a noop handler provided, all transactions are considered valid. Please note that vote extensions will only be available on the following height in which vote extensions are enabled. More information about vote extensions can be found [here](https://docs.cosmos.network/main/build/abci/vote-extensions). diff --git a/docs/build/abci/01-prepare-proposal.md b/docs/build/abci/01-prepare-proposal.md index c77c9094d450..3d480664e5a4 100644 --- a/docs/build/abci/01-prepare-proposal.md +++ b/docs/build/abci/01-prepare-proposal.md @@ -24,12 +24,12 @@ it would like the block constructed. The Cosmos SDK defines the `DefaultProposalHandler` type, which provides applications with `PrepareProposal` and `ProcessProposal` handlers. If you decide to implement your -own `PrepareProposal` handler, you must be sure to ensure that the transactions +own `PrepareProposal` handler, you must ensure that the transactions selected DO NOT exceed the maximum block gas (if set) and the maximum bytes provided by `req.MaxBytes`. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci_utils.go +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/baseapp/abci_utils.go ``` This default implementation can be overridden by the application developer in @@ -38,7 +38,7 @@ favor of a custom implementation in [`app_di.go`](https://docs.cosmos.network/ma ```go prepareOpt := func(app *baseapp.BaseApp) { abciPropHandler := baseapp.NewDefaultProposalHandler(mempool, app) - app.SetPrepareProposal(abciPropHandler.PrepareProposalHandler())) + app.SetPrepareProposal(abciPropHandler.PrepareProposalHandler()) } baseAppOptions = append(baseAppOptions, prepareOpt) diff --git a/docs/build/abci/02-process-proposal.md b/docs/build/abci/02-process-proposal.md index 834ba3b90c48..7768890bdae9 100644 --- a/docs/build/abci/02-process-proposal.md +++ b/docs/build/abci/02-process-proposal.md @@ -14,12 +14,12 @@ and `ProcessProposal` for the new proposal. Here is the implementation of the default implementation: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci_utils.go#L153-L159 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/baseapp/abci_utils.go#L224-L231 ``` Like `PrepareProposal` this implementation is the default and can be modified by the application developer in [`app_di.go`](https://docs.cosmos.network/main/build/building-apps/app-go-di). If you decide to implement -your own `ProcessProposal` handler, you must be sure to ensure that the transactions +your own `ProcessProposal` handler, you must ensure that the transactions provided in the proposal DO NOT exceed the maximum block gas and `maxtxbytes` (if set). ```go diff --git a/docs/build/abci/03-vote-extensions.md b/docs/build/abci/03-vote-extensions.md index 59b00c89854a..26cbfd1a296d 100644 --- a/docs/build/abci/03-vote-extensions.md +++ b/docs/build/abci/03-vote-extensions.md @@ -8,7 +8,7 @@ defined in ABCI++. ## Extend Vote ABCI2.0 (colloquially called ABCI++) allows an application to extend a pre-commit vote with arbitrary data. This process does NOT have to be deterministic, and the data returned can be unique to the -validator process. The Cosmos SDK defines [`baseapp.ExtendVoteHandler`](https://github.com/cosmos/cosmos-sdk/blob/v0.50.1/types/abci.go#L26-L27): +validator process. The Cosmos SDK defines [`baseapp.ExtendVoteHandler`](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/types/abci.go#L26-L27): ```go type ExtendVoteHandler func(Context, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) @@ -35,7 +35,7 @@ Click [here](https://docs.cosmos.network/main/build/abci/vote-extensions) if you Similar to extending a vote, an application can also verify vote extensions from other validators when validating their pre-commits. For a given vote extension, -this process MUST be deterministic. The Cosmos SDK defines [`sdk.VerifyVoteExtensionHandler`](https://github.com/cosmos/cosmos-sdk/blob/v0.50.1/types/abci.go#L29-L31): +this process MUST be deterministic. The Cosmos SDK defines [`sdk.VerifyVoteExtensionHandler`](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/types/abci.go#L29-L31): ```go type VerifyVoteExtensionHandler func(Context, *abci.VerifyVoteExtensionRequest) (*abci.VerifyVoteExtensionResponse, error) diff --git a/docs/build/abci/04-checktx.md b/docs/build/abci/04-checktx.md new file mode 100644 index 000000000000..a2c5f2d707d6 --- /dev/null +++ b/docs/build/abci/04-checktx.md @@ -0,0 +1,50 @@ +# CheckTx + +CheckTx is called by the `BaseApp` when comet receives a transaction from a client, over the p2p network or RPC. The CheckTx method is responsible for validating the transaction and returning an error if the transaction is invalid. + +```mermaid +graph TD + subgraph SDK[Cosmos SDK] + B[Baseapp] + A[AnteHandlers] + B <-->|Validate TX| A + end + C[CometBFT] <-->|CheckTx|SDK + U((User)) -->|Submit TX| C + N[P2P] -->|Receive TX| C +``` + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/31c604762a434c7b676b6a89897ecbd7c4653a23/baseapp/abci.go#L350-L390 +``` + +## CheckTx Handler + +`CheckTxHandler` allows users to extend the logic of `CheckTx`. `CheckTxHandler` is called by pasding context and the transaction bytes received through ABCI. It is required that the handler returns deterministic results given the same transaction bytes. + +:::note +we return the raw decoded transaction here to avoid decoding it twice. +::: + +```go +type CheckTxHandler func(ctx sdk.Context, tx []byte) (Tx, error) +``` + +Setting a custom `CheckTxHandler` is optional. It can be done from your app.go file: + +```go +func NewSimApp( + logger log.Logger, + db corestore.KVStoreWithBatch, + traceStore io.Writer, + loadLatest bool, + appOpts servertypes.AppOptions, + baseAppOptions ...func(*baseapp.BaseApp), +) *SimApp { + ... + // Create ChecktxHandler + checktxHandler := abci.NewCustomCheckTxHandler(...) + app.SetCheckTxHandler(checktxHandler) + ... +} +``` diff --git a/docs/build/building-apps/02-app-mempool.md b/docs/build/building-apps/02-app-mempool.md index 45719af4824d..d22832b3f166 100644 --- a/docs/build/building-apps/02-app-mempool.md +++ b/docs/build/building-apps/02-app-mempool.md @@ -22,7 +22,7 @@ Notably it introduces the `PrepareProposal` and `ProcessProposal` steps of ABCI+ ## Mempool -+ Before we delve into `PrepareProposal` and `ProcessProposal`, let's first walk through the mempool concepts. +* Before we delve into `PrepareProposal` and `ProcessProposal`, let's first walk through the mempool concepts. There are countless designs that an application developer can write for a mempool, the SDK opted to provide only simple mempool implementations. Namely, the SDK provides the following mempools: diff --git a/docs/build/building-apps/06-system-tests.md b/docs/build/building-apps/06-system-tests.md new file mode 100644 index 000000000000..eb6d61ffea46 --- /dev/null +++ b/docs/build/building-apps/06-system-tests.md @@ -0,0 +1,58 @@ +--- +sidebar_position: 1 +--- + +# System Tests + +System tests provide a framework to write and execute black box tests against a running chain. This adds another level +of confidence on top of unit, integration, and simulations tests, ensuring that business-critical scenarios +(like double signing prevention) or scenarios that can't be tested otherwise (like a chain upgrade) are covered. + +## Vanilla Go for Flow Control + +System tests are vanilla Go tests that interact with the compiled chain binary. The `test runner` component starts a +local testnet of 4 nodes (by default) and provides convenient helper methods for accessing the +`system under test (SUT)`. +A `CLI wrapper` makes it easy to access keys, submit transactions, or execute operations. Together, these components +enable the replication and validation of complex business scenarios. + +Here's an example of a double signing test, where a new node is added with the same key as the first validator: +[double signing test example](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/fraud_test.go) + +The [getting started tutorial](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/tests/systemtests/getting_started.md) +contains a step-by-step guide to building and running your first system test. It covers setting chain state via genesis +or +transactions and validation via transaction response or queries. + +## Design Principles and Guidelines + +System tests are slower compared to unit or integration tests as they interact with a running chain. Therefore, certain +principles can guide their usage: + +- **Perspective:** Tests should mimic a human interacting with the chain from the outside. Initial states can be set via + genesis or transactions to support a test scenario. +- **Roles:** The user can have multiple roles such as validator, delegator, granter, or group admin. +- **Focus:** Tests should concentrate on happy paths or business-critical workflows. Unit and integration tests are + better suited for more fine-grained testing. +- **Workflows:** Test workflows and scenarios, not individual units. Given the high setup costs, it is reasonable to + combine multiple steps and assertions in a single test method. +- **Genesis Mods:** Genesis modifications can incur additional time costs for resetting dirty states. Reuse existing + accounts (node0..n) whenever possible. +- **Framework:** Continuously improve the framework for better readability and reusability. + +## Errors and Debugging + +All output is logged to `systemtests/testnet/node{0..n}.out`. Usually, `node0.out` is very noisy as it receives the CLI +connections. Prefer any other node's log to find stack traces or error messages. + +Using system tests for state setup during debugging has become very handy: + +- Start the test with one node only and verbose output: + + ```sh + go test -v -tags=system_test ./ --run TestAccountCreation --verbose --nodes-count=1 + ``` + +- Copy the CLI command for the transaction and modify the test to stop before the command +- Start the node with `--home=/tests/systemtests/testnet/node0//` in debug mode +- Execute CLI command from shell and enter breakpoints diff --git a/docs/build/building-modules/01-module-manager.md b/docs/build/building-modules/01-module-manager.md index d5e0aac04daa..8ffc2ee59bbf 100644 --- a/docs/build/building-modules/01-module-manager.md +++ b/docs/build/building-modules/01-module-manager.md @@ -125,16 +125,6 @@ Previously the `module.AppModule` interface was containing all the methods that https://github.com/cosmos/cosmos-sdk/blob/28fa3b8/core/appmodule/v2/module.go#L14-L20 ``` -### `HasInvariants` - -This interface defines one method. It allows to checks if a module can register invariants. - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/module/module.go#L202-L205 -``` - -* `RegisterInvariants(sdk.InvariantRegistry)`: Registers the [`invariants`](./07-invariants.md) of the module. If an invariant deviates from its predicted value, the [`InvariantRegistry`](./07-invariants.md#registry) triggers appropriate logic (most often the chain will be halted). - ### `HasServices` This interface defines one method. It allows to checks if a module can register invariants. @@ -238,14 +228,13 @@ The module manager is used throughout the application whenever an action on a co * `SetOrderPrecommiters(moduleNames ...string)`: Sets the order in which the `Precommit()` function of each module will be called during commit of each block. This function is generally called from the application's main [constructor function](../../learn/beginner/00-app-anatomy.md#constructor-function). * `SetOrderPrepareCheckStaters(moduleNames ...string)`: Sets the order in which the `PrepareCheckState()` function of each module will be called during commit of each block. This function is generally called from the application's main [constructor function](../../learn/beginner/00-app-anatomy.md#constructor-function). * `SetOrderMigrations(moduleNames ...string)`: Sets the order of migrations to be run. If not set then migrations will be run with an order defined in `DefaultMigrationsOrder`. -* `RegisterInvariants(ir sdk.InvariantRegistry)`: Registers the [invariants](./07-invariants.md) of module implementing the `HasInvariants` interface. * `RegisterServices(cfg Configurator)`: Registers the services of modules implementing the `HasServices` interface. * `InitGenesis(ctx context.Context, genesisData map[string]json.RawMessage)`: Calls the [`InitGenesis`](./08-genesis.md#initgenesis) function of each module when the application is first started, in the order defined in `OrderInitGenesis`. Returns an `abci.InitChainResponse` to the underlying consensus engine, which can contain validator updates. * `ExportGenesis(ctx context.Context)`: Calls the [`ExportGenesis`](./08-genesis.md#exportgenesis) function of each module, in the order defined in `OrderExportGenesis`. The export constructs a genesis file from a previously existing state, and is mainly used when a hard-fork upgrade of the chain is required. * `ExportGenesisForModules(ctx context.Context, modulesToExport []string)`: Behaves the same as `ExportGenesis`, except takes a list of modules to export. -* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./06-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from each modules. -* `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). -* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). +* `BeginBlock(ctx context.Context) error`: At the beginning of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#beginblock) and, in turn, calls the [`BeginBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasBeginBlocker` interface, in the order defined in `OrderBeginBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from each modules. +* `EndBlock(ctx context.Context) error`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `appmodule.HasEndBlocker` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). +* `EndBlock(context.Context) ([]abci.ValidatorUpdate, error)`: At the end of each block, this function is called from [`BaseApp`](../../learn/advanced/00-baseapp.md#endblock) and, in turn, calls the [`EndBlock`](./06-preblock-beginblock-endblock.md) function of each modules implementing the `module.HasABCIEndBlock` interface, in the order defined in `OrderEndBlockers`. It creates a child [context](../../learn/advanced/02-context.md) with an event manager to aggregate [events](../../learn/advanced/08-events.md) emitted from all modules. The function returns an `abci` which contains the aforementioned events, as well as validator set updates (if any). * `Precommit(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately before the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `Precommit` function of each modules implementing the `HasPrecommit` interface, in the order defined in `OrderPrecommiters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the newly committed block's [`finalizeblockstate`](../../learn/advanced/00-baseapp.md#state-updates). * `PrepareCheckState(ctx context.Context)`: During [`Commit`](../../learn/advanced/00-baseapp.md#commit), this function is called from `BaseApp` immediately after the [`deliverState`](../../learn/advanced/00-baseapp.md#state-updates) is written to the underlying [`rootMultiStore`](../../learn/advanced/04-store.md#commitmultistore) and, in turn calls the `PrepareCheckState` function of each module implementing the `HasPrepareCheckState` interface, in the order defined in `OrderPrepareCheckStaters`. It creates a child [context](../../learn/advanced/02-context.md) where the underlying `CacheMultiStore` is that of the next block's [`checkState`](../../learn/advanced/00-baseapp.md#state-updates). Writes to this state will be present in the [`checkState`](../../learn/advanced/00-baseapp.md#state-updates) of the next block, and therefore this method can be used to prepare the `checkState` for the next block. * (Optional) `RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)`: Registers the [`codec.LegacyAmino`s](../../learn/advanced/05-encoding.md#amino) of each of the application module. This function is usually called early on in the [application's construction](../../learn/beginner/00-app-anatomy.md#constructor). diff --git a/docs/build/building-modules/06-beginblock-endblock.md b/docs/build/building-modules/06-preblock-beginblock-endblock.md similarity index 62% rename from docs/build/building-modules/06-beginblock-endblock.md rename to docs/build/building-modules/06-preblock-beginblock-endblock.md index 21c1a3303d3f..a7a890eff19c 100644 --- a/docs/build/building-modules/06-beginblock-endblock.md +++ b/docs/build/building-modules/06-preblock-beginblock-endblock.md @@ -2,10 +2,11 @@ sidebar_position: 1 --- -# BeginBlocker and EndBlocker +# PreBlocker, BeginBlocker and EndBlocker :::note Synopsis -`BeginBlocker` and `EndBlocker` are optional methods module developers can implement in their module. They will be triggered at the beginning and at the end of each block respectively, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) ABCI messages are received from the underlying consensus engine. +`PreBlocker`, `BeginBlocker` and `EndBlocker` are optional methods module developers can implement in their module. +They will be triggered at the beginning and at the end of each block respectively, when the [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock) and [`EndBlock`](../../learn/advanced/00-baseapp.md#endblock) inside within ABCI `FinalizeBlock` ::: :::note Pre-requisite Readings @@ -14,11 +15,22 @@ sidebar_position: 1 ::: +## PreBlocker + +There are two semantics around the new lifecycle method: + +* It runs before the `BeginBlocker` of all modules +* It can modify consensus parameters in storage, and signal the caller through the return value. + +:::warning +Modules are required to get the consensus params from the consensus module. Consensus params located in `sdk.Context` were deprecated and should be treated as unsafe. `sdk.Context` is deprecated due to it being a global state within the entire state machine, it has been replaced with `appmodule.Environment`. +::: + ## BeginBlocker and EndBlocker `BeginBlocker` and `EndBlocker` are a way for module developers to add automatic execution of logic to their module. This is a powerful tool that should be used carefully, as complex automatic functions can slow down or even halt the chain. -In 0.47.0, Prepare and Process Proposal were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in BeginBlock. If an application required `BeginBlock` to execute prior to any sort of work is done then this is not possible today (0.50.0). +In 0.47.0, `PrepareProposal` and `ProcessProposal` were added that allow app developers to do arbitrary work at those phases, but they do not influence the work that will be done in `BeginBlock`, nor are they accessible from modules. When needed, `BeginBlocker` and `EndBlocker` are implemented as part of the [`HasBeginBlocker`, `HasABCIEndBlocker` and `EndBlocker` interfaces](./01-module-manager.md#appmodule). This means either can be left-out if not required. The `BeginBlock` and `EndBlock` methods of the interface implemented in `module.go` generally defer to `BeginBlocker` and `EndBlocker` methods respectively, which are usually implemented in `abci.go`. @@ -28,10 +40,18 @@ The actual implementation of `BeginBlocker` and `EndBlocker` in `abci.go` are ve * If needed, they use the `keeper` and `ctx` to trigger state-transitions. * If needed, they can emit [`events`](../../learn/advanced/08-events.md) via the `environments`'s `EventManager`. -A specific method (`UpdateValidators`) is available to return validator updates to the underlying consensus engine in the form of an [`[]appmodule.ValidatorUpdates`](https://github.com/cosmos/cosmos-sdk/blob/07151304e2ec6a185243d083f59a2d543253cb15/core/appmodule/v2/module.go#L87-L101). This is the preferred way to implement custom validator changes. +A specific method (`UpdateValidators`) is available to return validator updates to the underlying consensus engine in the form of an [`[]appmodule.ValidatorUpdates`](https://github.com/cosmos/cosmos-sdk/blob/07151304e2ec6a185243d083f59a2d543253cb15/core/appmodule/v2/module.go#L87-L101). This is the preferred way to implement custom validator changes (in v1). It is possible for developers to define the order of execution between the `BeginBlocker`/`EndBlocker` functions of each of their application's modules via the module's manager `SetOrderBeginBlocker`/`SetOrderEndBlocker` methods. For more on the module manager, click [here](./01-module-manager.md#manager). +### Implementation + +A module must implement those core interface to make use of the `PreBlocker`, `BeginBlocker` or `EndBlocker` capabilities: + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/core/v1.0.0-alpha.4/core/appmodule/v2/module.go#L22-L48 +``` + See an example implementation of `BeginBlocker` from the `distribution` module: ```go reference @@ -49,6 +69,3 @@ and an example implementation of `EndBlocker` with validator updates from the `s ```go reference https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/keeper/abci.go#L12-L17 ``` - - - diff --git a/docs/build/building-modules/07-invariants.md b/docs/build/building-modules/07-invariants.md deleted file mode 100644 index 2e8edfcada68..000000000000 --- a/docs/build/building-modules/07-invariants.md +++ /dev/null @@ -1,92 +0,0 @@ ---- -sidebar_position: 1 ---- - -# Invariants - - - -:::note Synopsis -An invariant is a property of the application that should always be true. In the context of the Cosmos SDK, an `Invariant` is a function that checks for a particular invariant. These functions are useful to detect bugs early on and act upon them to limit their potential consequences (e.g. by halting the chain). They are also useful in the development process of the application to detect bugs via simulations. -::: - -:::note Pre-requisite Readings - -* [Keepers](./06-keeper.md) - -::: - -## Implementing `Invariant`s - -An `Invariant` is a function that checks for a particular invariant within a module. Module `Invariant`s must follow the `Invariant` type: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/invariant.go#L9 -``` - -The `string` return value is the invariant message, which can be used when printing logs, and the `bool` return value is the actual result of the invariant check. - -In practice, each module implements `Invariant`s in a `keeper/invariants.go` file within the module's folder. The standard is to implement one `Invariant` function per logical grouping of invariants with the following model: - -```go -// Example for an Invariant that checks balance-related invariants - -func BalanceInvariants(k Keeper) sdk.Invariant { - return func(ctx context.Context) (string, bool) { - // Implement checks for balance-related invariants - } -} -``` - -Additionally, module developers should generally implement an `AllInvariants` function that runs all the `Invariant`s functions of the module: - -```go -// AllInvariants runs all invariants of the module. -// In this example, the module implements two Invariants: BalanceInvariants and DepositsInvariants - -func AllInvariants(k Keeper) sdk.Invariant { - - return func(ctx context.Context) (string, bool) { - res, stop := BalanceInvariants(k)(ctx) - if stop { - return res, stop - } - - return DepositsInvariant(k)(ctx) - } -} -``` - -Finally, module developers need to implement the `RegisterInvariants` method as part of the [`AppModule` interface](./01-module-manager.md#appmodule). Indeed, the `RegisterInvariants` method of the module, implemented in the `module/module.go` file, typically only defers the call to a `RegisterInvariants` method implemented in the `keeper/invariants.go` file. The `RegisterInvariants` method registers a route for each `Invariant` function in the [`InvariantRegistry`](#invariant-registry): - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/staking/keeper/invariants.go#L12-L22 -``` - -For more, see an example of [`Invariant`s implementation from the `staking` module](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/staking/keeper/invariants.go). - -## Invariant Registry - -The `InvariantRegistry` is a registry where the `Invariant`s of all the modules of an application are registered. There is only one `InvariantRegistry` per **application**, meaning module developers need not implement their own `InvariantRegistry` when building a module. **All module developers need to do is to register their modules' invariants in the `InvariantRegistry`, as explained in the section above**. The rest of this section gives more information on the `InvariantRegistry` itself, and does not contain anything directly relevant to module developers. - -At its core, the `InvariantRegistry` is defined in the Cosmos SDK as an interface: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/types/invariant.go#L14-L17 -``` - -Typically, this interface is implemented in the `keeper` of a specific module. The most used implementation of an `InvariantRegistry` can be found in the `crisis` module: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/crisis/keeper/keeper.go#L48-L50 -``` - -The `InvariantRegistry` is therefore typically instantiated by instantiating the `keeper` of the `crisis` module in the [application's constructor function](../../learn/beginner/00-app-anatomy.md#constructor-function). - -`Invariant`s can be checked manually via [`message`s](./02-messages-and-queries.md), but most often they are checked automatically at the end of each block. Here is an example from the `crisis` module: - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/crisis/abci.go#L13-L23 -``` - -In both cases, if one of the `Invariant`s returns false, the `InvariantRegistry` can trigger special logic (e.g. have the application panic and print the `Invariant`s message in the log). diff --git a/docs/build/building-modules/16-testing.md b/docs/build/building-modules/16-testing.md index f2fafa36fd9d..65ed52a8a142 100644 --- a/docs/build/building-modules/16-testing.md +++ b/docs/build/building-modules/16-testing.md @@ -86,38 +86,26 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/tests/integration/bank ## Simulations -Simulations uses as well a minimal application, built with [`depinject`](../packages/01-depinject.md): +Simulations fuzz tests for deterministic message execution. They use a minimal application, built with [`depinject`](../packages/01-depinject.md): :::note -You can as well use the `AppConfig` `configurator` for creating an `AppConfig` [inline](https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/slashing/app_test.go#L54-L62). There is no difference between those two ways, use whichever you prefer. +Simulations have been refactored to message factories ::: -Following is an example for `x/gov/` simulations: +An example for `x/bank/` simulations: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/gov/simulation/operations_test.go#L406-L430 +https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/bank/simulation/msg_factory.go#L13-L20 ``` -```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/x/gov/simulation/operations_test.go#L90-L132 -``` - -## End-to-end Tests +## System Tests -End-to-end tests are at the top of the [test pyramid](https://martinfowler.com/articles/practical-test-pyramid.html). -They must test the whole application flow, from the user perspective (for instance, CLI tests). They are located under [`/tests/e2e`](https://github.com/cosmos/cosmos-sdk/tree/main/tests/e2e). +System tests are at the top of the [test pyramid](https://martinfowler.com/articles/practical-test-pyramid.html). +They test the whole application flow as black box, from the user perspective. They are located under [`/tests/systemtests`](https://github.com/cosmos/cosmos-sdk/tree/main/tests/systemtests). - -For that, the SDK is using `simapp` but you should use your own application (`appd`). -Here are some examples: +For that, the SDK is using the `simapp` binary, but you should use your own binary. +More details about system test can be found in [building-apps](https://docs.cosmos.network/main/build/building-apps/06-system-tests.md) -* SDK E2E tests: . -* Cosmos Hub E2E tests: . -* Osmosis E2E tests: . - -:::note warning -The SDK is in the process of creating its E2E tests, as defined in [ADR-59](https://docs.cosmos.network/main/build/architecture/adr-059-test-scopes). This page will eventually be updated with better examples. -::: ## Learn More diff --git a/docs/build/building-modules/17-preblock.md b/docs/build/building-modules/17-preblock.md deleted file mode 100644 index 81c81bd94b63..000000000000 --- a/docs/build/building-modules/17-preblock.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -sidebar_position: 1 ---- - -# PreBlocker - -:::note Synopsis -`PreBlocker` is optional method module developers can implement in their module. They will be triggered before [`BeginBlock`](../../learn/advanced/00-baseapp.md#beginblock). -::: - -:::note Pre-requisite Readings - -* [Module Manager](./01-module-manager.md) - -::: - -## PreBlocker - -There are two semantics around the new lifecycle method: - -* It runs before the `BeginBlocker` of all modules -* It can modify consensus parameters in storage, and signal the caller through the return value. - -Modules are required to get the consensus params from the consensus module. Consensus params located in `sdk.Context` were deprecated and should be treated as unsafe. `sdk.Context` is deprecated due to it being a global state within the entire state machine, it has been replaced with `appmodule.Environment`. diff --git a/docs/build/packages/README.md b/docs/build/packages/README.md index ce70c52e2b56..cbb150f501b3 100644 --- a/docs/build/packages/README.md +++ b/docs/build/packages/README.md @@ -14,26 +14,40 @@ For more information on SDK tooling, see the [Tooling](https://docs.cosmos.netwo ## Core -* [Core](https://pkg.go.dev/cosmossdk.io/core) - Core library defining SDK interfaces ([ADR-063](https://docs.cosmos.network/main/architecture/adr-063-core-module-api)) +* [Core](https://pkg.go.dev/cosmossdk.io/core) - Core library defining SDK modules and Server core interfaces ([ADR-063](https://docs.cosmos.network/main/architecture/adr-063-core-module-api)) * [API](https://pkg.go.dev/cosmossdk.io/api) - API library containing generated SDK Pulsar API * [Store](https://pkg.go.dev/cosmossdk.io/store) - Implementation of the Cosmos SDK store +* [Store/v2](https://pkg.go.dev/cosmossdk.io/store/v2) - Implementation of the Cosmos SDK store + +## V2 + +* [Server/v2/stf](https://pkg.go.dev/cosmossdk.io/server/v2/stf) - State Transition Function (STF) library for Cosmos SDK v2 +* [Server/v2/appmanager](https://pkg.go.dev/cosmossdk.io/server/v2/appmanager) - App coordinator for Cosmos SDK v2 +* [runtime/v2](https://pkg.go.dev/cosmossdk.io/runtime/v2) - Runtime library for Cosmos SDK v2 +* [Server/v2](https://pkg.go.dev/cosmossdk.io/server/v2) - Global server library for Cosmos SDK v2 +* [Server/v2/cometbft](https://pkg.go.dev/cosmossdk.io/server/v2/cometbft) - CometBFT Server implementation for Cosmos SDK v2 ## State Management * [Collections](./02-collections.md) - State management library * [ORM](./03-orm.md) - State management library +* [Schema](https://pkg.go.dev/cosmossdk.io/schema) - Logical representation of module state schemas +* [PostgreSQL indexer](https://pkg.go.dev/cosmossdk.io/indexer/postgres) - PostgreSQL indexer for Cosmos SDK modules -## Automation +## UX * [Depinject](./01-depinject.md) - Dependency injection framework * [Client/v2](https://pkg.go.dev/cosmossdk.io/client/v2) - Library powering [AutoCLI](https://docs.cosmos.network/main/core/autocli) ## Utilities +* [Core/Testing](https://pkg.go.dev/cosmossdk.io/core/testing) - Mocking library for SDK modules * [Log](https://pkg.go.dev/cosmossdk.io/log) - Logging library * [Errors](https://pkg.go.dev/cosmossdk.io/errors) - Error handling library +* [Errors/v2](https://pkg.go.dev/cosmossdk.io/errors/v2) - Error handling library * [Math](https://pkg.go.dev/cosmossdk.io/math) - Math library for SDK arithmetic operations ## Example +* [SimApp v2](https://pkg.go.dev/cosmossdk.io/simapp/v2) - SimApp/v2 is **the** sample Cosmos SDK v2 chain. This package should not be imported in your application. * [SimApp](https://pkg.go.dev/cosmossdk.io/simapp) - SimApp is **the** sample Cosmos SDK chain. This package should not be imported in your application. diff --git a/docs/build/tooling/00-protobuf.md b/docs/build/tooling/00-protobuf.md index d9a210a78577..849a7974eab7 100644 --- a/docs/build/tooling/00-protobuf.md +++ b/docs/build/tooling/00-protobuf.md @@ -4,21 +4,17 @@ sidebar_position: 1 # Protocol Buffers -It is known that Cosmos SDK uses protocol buffers extensively, this document is meant to provide a guide on how it is used in the cosmos-sdk. +Cosmos SDK uses protocol buffers extensively, this document is meant to provide a guide on how it is used in the cosmos-sdk. -To generate the proto file, the Cosmos SDK uses a docker image, this image is provided to all to use as well. The latest version is `ghcr.io/cosmos/proto-builder:0.12.x` +To generate the proto file, the Cosmos SDK uses a docker image, this image is provided to all to use as well. The latest version is `ghcr.io/cosmos/proto-builder:0.15.x` Below is the example of the Cosmos SDK's commands for generating, linting, and formatting protobuf files that can be reused in any applications makefile. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/Makefile#L411-L432 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/scripts/build/protobuf.mk#L1-L10 ``` -The script used to generate the protobuf files can be found in the `scripts/` directory. - -```shell reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/scripts/protocgen.sh -``` +The [`protocgen.sh`](https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/scripts/protocgen.sh) script used to generate the protobuf files via buf can be found in the `scripts/` directory. ## Buf @@ -36,7 +32,9 @@ https://github.com/cosmos/cosmos-sdk/blob/main/buf.work.yaml#L6-L9 ### Proto Directory -Next is the `proto/` directory where all of our protobuf files live. In here there are many different buf files defined each serving a different purpose. +The `proto/` directory where all of global protobuf files live. +In here there are many different buf files defined each serving a different purpose. +Modules proto files are defined in their respective module directories (in the SDK `x/{moduleName}/proto`). ```bash ├── README.md @@ -50,8 +48,6 @@ Next is the `proto/` directory where all of our protobuf files live. In here the └── tendermint ``` -The above diagram all the files and directories within the Cosmos SDK `proto/` directory. - #### `buf.gen.gogo.yaml` `buf.gen.gogo.yaml` defines how the protobuf files should be generated for use with in the module. This file uses [gogoproto](https://github.com/gogo/protobuf), a separate generator from the google go-proto generator that makes working with various objects more ergonomic, and it has more performant encode and decode steps @@ -60,10 +56,6 @@ The above diagram all the files and directories within the Cosmos SDK `proto/` d https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.gogo.yaml#L1-L9 ``` -:::tip -Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code) -::: - #### `buf.gen.pulsar.yaml` `buf.gen.pulsar.yaml` defines how protobuf files should be generated using the [new golang apiv2 of protobuf](https://go.dev/blog/protobuf-apiv2). This generator is used instead of the google go-proto generator because it has some extra helpers for Cosmos SDK applications and will have more performant encode and decode than the google go-proto generator. You can follow the development of this generator [here](https://github.com/cosmos/cosmos-proto). @@ -72,10 +64,6 @@ Example of how to define `gen` files can be found [here](https://docs.buf.build/ https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.pulsar.yaml#L1-L18 ``` -:::tip -Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code) -::: - #### `buf.gen.swagger.yaml` `buf.gen.swagger.yaml` generates the swagger documentation for the query and messages of the chain. This will only define the REST API end points that were defined in the query and msg servers. You can find examples of this [here](https://github.com/cosmos/cosmos-sdk/blob/main/x/bank/proto/cosmos/bank/v1beta1/query.proto) @@ -84,10 +72,6 @@ Example of how to define `gen` files can be found [here](https://docs.buf.build/ https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.gen.swagger.yaml#L1-L6 ``` -:::tip -Example of how to define `gen` files can be found [here](https://docs.buf.build/tour/generate-go-code) -::: - #### `buf.lock` This is an autogenerated file based off the dependencies required by the `.gen` files. There is no need to copy the current one. If you depend on cosmos-sdk proto definitions a new entry for the Cosmos SDK will need to be provided. The dependency you will need to use is `buf.build/cosmos/cosmos-sdk`. @@ -100,14 +84,11 @@ https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.lock#L1-L16 `buf.yaml` defines the [name of your package](https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.yaml#L3), which [breakage checker](https://buf.build/docs/tutorials/getting-started-with-buf-cli#detect-breaking-changes) to use and how to [lint your protobuf files](https://buf.build/docs/tutorials/getting-started-with-buf-cli#lint-your-api). +It is advised to use a tagged version of the buf modules corresponding to the version of the Cosmos SDK being are used. + ```go reference https://github.com/cosmos/cosmos-sdk/blob/main/proto/buf.yaml#L1-L24 ``` We use a variety of linters for the Cosmos SDK protobuf files. The repo also checks this in ci. - A reference to the github actions can be found [here](https://github.com/cosmos/cosmos-sdk/blob/main/.github/workflows/proto.yml#L1-L32) - -```go reference -https://github.com/cosmos/cosmos-sdk/blob/main/.github/workflows/proto.yml#L1-L32 -``` diff --git a/docs/learn/advanced/00-baseapp.md b/docs/learn/advanced/00-baseapp.md index 20968f91bd0f..46f6cce403f0 100644 --- a/docs/learn/advanced/00-baseapp.md +++ b/docs/learn/advanced/00-baseapp.md @@ -394,9 +394,9 @@ The `AnteHandler` operates on a copy of the cached context, allowing it to perfo Key operations performed by the `AnteHandler` include: -- **Signature Verification**: Ensures that the transaction's signatures are valid. -- **Sequence Checking**: Verifies and increments the sequence numbers to prevent replay attacks. -- **Fee Deduction**: Deducts the transaction fees from the accounts involved, typically starting with the first signer. +* **Signature Verification**: Ensures that the transaction's signatures are valid. +* **Sequence Checking**: Verifies and increments the sequence numbers to prevent replay attacks. +* **Fee Deduction**: Deducts the transaction fees from the accounts involved, typically starting with the first signer. These operations are crucial for maintaining the security and integrity of transactions on the blockchain. @@ -460,7 +460,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci.go#L623 #### PreBlock -* Run the application's [`preBlocker()`](../beginner/00-app-anatomy.md#preblocker), which mainly runs the [`PreBlocker()`](../../build/building-modules/17-preblock.md#preblock) method of each of the modules. +* Run the application's [`preBlocker()`](../beginner/00-app-anatomy.md#preblocker), which mainly runs the [`PreBlocker()`](../../build/building-modules/06-preblock-beginblock-endblock.md#preblock) method of each of the modules. #### BeginBlock @@ -473,7 +473,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/baseapp/abci.go#L623 This function also resets the [main gas meter](../beginner/04-gas-fees.md#main-gas-meter). * Initialize the [block gas meter](../beginner/04-gas-fees.md#block-gas-meter) with the `maxGas` limit. The `gas` consumed within the block cannot go above `maxGas`. This parameter is defined in the application's consensus parameters. -* Run the application's [`beginBlocker()`](../beginner/00-app-anatomy.md#beginblocker-and-endblocker), which mainly runs the [`BeginBlocker()`](../../build/building-modules/06-beginblock-endblock.md#beginblock) method of each of the modules. +* Run the application's [`beginBlocker()`](../beginner/00-app-anatomy.md#beginblocker-and-endblocker), which mainly runs the [`BeginBlocker()`](../../build/building-modules/06-preblock-beginblock-endblock.md#beginblock) method of each of the modules. * Set the [`VoteInfos`](https://docs.cometbft.com/v1.0/spec/abci/abci++_methods#voteinfo) of the application, i.e. the list of validators whose _precommit_ for the previous block was included by the proposer of the current block. This information is carried into the [`Context`](./02-context.md) so that it can be used during transaction execution and EndBlock. #### Transaction Execution diff --git a/docs/learn/beginner/00-app-anatomy.md b/docs/learn/beginner/00-app-anatomy.md index 9757e7e95af3..1e94ae52c3de 100644 --- a/docs/learn/beginner/00-app-anatomy.md +++ b/docs/learn/beginner/00-app-anatomy.md @@ -87,7 +87,6 @@ Here are the main actions performed by this function: * Instantiate all the [`keeper`](#keeper) objects defined in the application's `type` using the `NewKeeper` function of each of the application's modules. Note that keepers must be instantiated in the correct order, as the `NewKeeper` of one module might require a reference to another module's `keeper`. * Instantiate the application's [module manager](../../build/building-modules/01-module-manager.md#manager) with the [`AppModule`](#application-module-interface) object of each of the application's modules. * With the module manager, initialize the application's [`Msg` services](../advanced/00-baseapp.md#msg-services), [gRPC `Query` services](../advanced/00-baseapp.md#grpc-query-services), [legacy `Msg` routes](../advanced/00-baseapp.md#routing), and [legacy query routes](../advanced/00-baseapp.md#query-routing). When a transaction is relayed to the application by CometBFT via the ABCI, it is routed to the appropriate module's [`Msg` service](#msg-services) using the routes defined here. Likewise, when a gRPC query request is received by the application, it is routed to the appropriate module's [`gRPC query service`](#grpc-query-services) using the gRPC routes defined here. The Cosmos SDK still supports legacy `Msg`s and legacy CometBFT queries, which are routed using the legacy `Msg` routes and the legacy query routes, respectively. -* With the module manager, register the [application's modules' invariants](../../build/building-modules/07-invariants.md). Invariants are variables (e.g. total supply of a token) that are evaluated at the end of each block. The process of checking invariants is done via a special module called the [`InvariantsRegistry`](../../build/building-modules/07-invariants.md#invariant-registry). The value of the invariant should be equal to a predicted value defined in the module. Should the value be different than the predicted one, special logic defined in the invariant registry is triggered (usually the chain is halted). This is useful to make sure that no critical bug goes unnoticed, producing long-lasting effects that are hard to fix. * With the module manager, set the order of execution between the `InitGenesis`, `PreBlocker`, `BeginBlocker`, and `EndBlocker` functions of each of the [application's modules](#application-module-interface). Note that not all modules implement these functions. * Set the remaining application parameters: * [`InitChainer`](#initchainer): used to initialize the application when it is first started. @@ -136,7 +135,7 @@ The new ctx must be passed to all the other lifecycle methods. The Cosmos SDK offers developers the possibility to implement automatic execution of code as part of their application. This is implemented through two functions called `BeginBlocker` and `EndBlocker`. They are called when the application receives the `FinalizeBlock` messages from the CometBFT consensus engine, which happens respectively at the beginning and at the end of each block. The application must set the `BeginBlocker` and `EndBlocker` in its [constructor](#constructor-function) via the [`SetBeginBlocker`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/baseapp#BaseApp.SetBeginBlocker) and [`SetEndBlocker`](https://pkg.go.dev/github.com/cosmos/cosmos-sdk/baseapp#BaseApp.SetEndBlocker) methods. -In general, the `BeginBlocker` and `EndBlocker` functions are mostly composed of the [`BeginBlock` and `EndBlock`](../../build/building-modules/06-beginblock-endblock.md) functions of each of the application's modules. This is done by calling the `BeginBlock` and `EndBlock` functions of the module manager, which in turn calls the `BeginBlock` and `EndBlock` functions of each of the modules it contains. Note that the order in which the modules' `BeginBlock` and `EndBlock` functions must be called has to be set in the module manager using the `SetOrderBeginBlockers` and `SetOrderEndBlockers` methods, respectively. This is done via the [module manager](../../build/building-modules/01-module-manager.md) in the [application's constructor](#constructor-function), and the `SetOrderBeginBlockers` and `SetOrderEndBlockers` methods have to be called before the `SetBeginBlocker` and `SetEndBlocker` functions. +In general, the `BeginBlocker` and `EndBlocker` functions are mostly composed of the [`BeginBlock` and `EndBlock`](../../build/building-modules/06-preblock-beginblock-endblock.md) functions of each of the application's modules. This is done by calling the `BeginBlock` and `EndBlock` functions of the module manager, which in turn calls the `BeginBlock` and `EndBlock` functions of each of the modules it contains. Note that the order in which the modules' `BeginBlock` and `EndBlock` functions must be called has to be set in the module manager using the `SetOrderBeginBlockers` and `SetOrderEndBlockers` methods, respectively. This is done via the [module manager](../../build/building-modules/01-module-manager.md) in the [application's constructor](#constructor-function), and the `SetOrderBeginBlockers` and `SetOrderEndBlockers` methods have to be called before the `SetBeginBlocker` and `SetEndBlocker` functions. As a sidenote, it is important to remember that application-specific blockchains are deterministic. Developers must be careful not to introduce non-determinism in `BeginBlocker` or `EndBlocker`, and must also be careful not to make them too computationally expensive, as [gas](./04-gas-fees.md) does not constrain the cost of `BeginBlocker` and `EndBlocker` execution. diff --git a/docs/learn/beginner/04-gas-fees.md b/docs/learn/beginner/04-gas-fees.md index 783a2228b829..63ac006a839f 100644 --- a/docs/learn/beginner/04-gas-fees.md +++ b/docs/learn/beginner/04-gas-fees.md @@ -52,7 +52,7 @@ By default, the Cosmos SDK makes use of two different gas meters, the [main gas `ctx.GasMeter()` is the main gas meter of the application. The main gas meter is initialized in `FinalizeBlock` via `setFinalizeBlockState`, and then tracks gas consumption during execution sequences that lead to state-transitions, i.e. those originally triggered by [`FinalizeBlock`](../advanced/00-baseapp.md#finalizeblock). At the beginning of each transaction execution, the main gas meter **must be set to 0** in the [`AnteHandler`](#antehandler), so that it can track gas consumption per-transaction. -Gas consumption can be done manually, generally by the module developer in the [`BeginBlocker`, `EndBlocker`](../../build/building-modules/06-beginblock-endblock.md) or [`Msg` service](../../build/building-modules/03-msg-services.md), but most of the time it is done automatically whenever there is a read or write to the store. This automatic gas consumption logic is implemented in a special store called [`GasKv`](../advanced/04-store.md#gaskv-store). +Gas consumption can be done manually, generally by the module developer in the [`BeginBlocker`, `EndBlocker`](../../build/building-modules/06-preblock-beginblock-endblock.md) or [`Msg` service](../../build/building-modules/03-msg-services.md), but most of the time it is done automatically whenever there is a read or write to the store. This automatic gas consumption logic is implemented in a special store called [`GasKv`](../advanced/04-store.md#gaskv-store). ### Block Gas Meter diff --git a/docs/learn/intro/00-overview.md b/docs/learn/intro/00-overview.md index bb32d84a962f..7b0a3da037b5 100644 --- a/docs/learn/intro/00-overview.md +++ b/docs/learn/intro/00-overview.md @@ -9,13 +9,13 @@ sidebar_position: 1 The [Cosmos SDK](https://github.com/cosmos/cosmos-sdk) is an open-source toolkit for building multi-asset public Proof-of-Stake (PoS) blockchains, like the Cosmos Hub, as well as permissioned Proof-of-Authority (PoA) blockchains. Blockchains built with the Cosmos SDK are generally referred to as **application-specific blockchains**. The goal of the Cosmos SDK is to allow developers to easily create custom blockchains from scratch that can natively interoperate with other blockchains. -We further this modular approach by allowing developers to plug and play with different consensus engines this can range from the [CometBFT](https://github.com/cometbft/cometbft) or [Rollkit](https://rollkit.dev/). +We further this modular approach by allowing developers to plug and play with different consensus engines this can range from [CometBFT](https://cometbft.com/) or [Rollkit](https://rollkit.dev/). SDK-based blockchains have the choice to use the predefined modules or to build their own modules. What this means is that developers can build a blockchain that is tailored to their specific use case, without having to worry about the low-level details of building a blockchain from scratch. Predefined modules include staking, governance, and token issuance, among others. What's more, the Cosmos SDK is a capabilities-based system that allows developers to better reason about the security of interactions between modules. For a deeper look at capabilities, jump to [Object-Capability Model](../advanced/10-ocap.md). -How you can look at this is if we imagine that the SDK is like a lego kit. You can choose to build the basic house from the instructions or you can choose to modify your house and add more floors, more doors, more windows. The choice is yours. +You can think of the SDK as a lego kit. You can choose to build the basic house from the instructions, or you can choose to modify your house and add more floors, more doors, more windows. The choice is yours. ## What are Application-Specific Blockchains @@ -27,17 +27,17 @@ Learn more about [application-specific blockchains](./01-why-app-specific.md). ## What is Modularity -Today there is a lot of talk around modularity and discussions between monolithic and modular. Originally the Cosmos SDK was built with a vision of modularity in mind. Modularity is derived from splitting a blockchain into customizable layers of execution, consensus, settlement and data availability, which is what the Cosmos SDK enables. This means that developers can plug and play, making their blockchain customisable by using different software for different layers. For example you can choose to build a vanilla chain and use the Cosmos SDK with CometBFT. CometBFT will be your consensus layer and the chain itself would be the settlement and execution layer. Another route could be to use the SDK with Rollkit and Celestia as your consensus and data availability layer. The benefit of modularity is that you can customize your chain to your specific use case. +Today, there is a lot of talk around modularity and discussions between monolithic and modular. Originally, the Cosmos SDK was built with a vision of modularity in mind. Modularity is derived from splitting a blockchain into customizable layers of execution, consensus, settlement and data availability, which is what the Cosmos SDK enables. This means that developers can plug and play, making their blockchain customizable by using different software for different layers. For example, you can choose to build a vanilla chain and use the Cosmos SDK with CometBFT. CometBFT will be your consensus layer and the chain itself would be the settlement and execution layer. Another route could be to use the SDK with Rollkit and [Celestia](https://celestia.org/) as your consensus and data availability layer. The benefit of modularity is that you can customize your chain to your specific use case. ## Why the Cosmos SDK The Cosmos SDK is the most advanced framework for building custom modular application-specific blockchains today. Here are a few reasons why you might want to consider building your decentralized application with the Cosmos SDK: -* It allows you to plug and play and customize your consensus layer. As above you can use Rollkit and Celestia as your consensus and data availability layer. This offers a lot of flexibility and customisation. -* Previously the default consensus engine available within the Cosmos SDK is [CometBFT](https://github.com/cometbft/cometbft). CometBFT is the most (and only) mature BFT consensus engine in existence. It is widely used across the industry and is considered the gold standard consensus engine for building Proof-of-Stake systems. +* It allows you to plug and play and customize your consensus layer. As mentioned above, you can use Rollkit and Celestia as your consensus and data availability layer. This offers a lot of flexibility and customization. +* Previously the default consensus engine available within the Cosmos SDK is [CometBFT](https://cometbft.com/). CometBFT is the most (and only) mature BFT consensus engine in existence. It is widely used across the industry and is considered the gold standard consensus engine for building Proof-of-Stake systems. * The Cosmos SDK is open-source and designed to make it easy to build blockchains out of composable [modules](../../build/modules). As the ecosystem of open-source Cosmos SDK modules grows, it will become increasingly easier to build complex decentralized platforms with it. * The Cosmos SDK is inspired by capabilities-based security, and informed by years of wrestling with blockchain state-machines. This makes the Cosmos SDK a very secure environment to build blockchains. -* Most importantly, the Cosmos SDK has already been used to build many application-specific blockchains that are already in production. Among others, we can cite [Cosmos Hub](https://hub.cosmos.network), [IRIS Hub](https://irisnet.org), [Binance Chain](https://docs.binance.org/), [Terra](https://terra.money/) or [Kava](https://www.kava.io/). [Many more](https://cosmos.network/ecosystem) are building on the Cosmos SDK. +* Most importantly, the Cosmos SDK has already been used to build many application-specific blockchains that are already in production. Among others, we can cite [Cosmos Hub](https://hub.cosmos.network), [Osmosis](https://osmosis.zone/), [Binance Chain](https://docs.binance.org/), [Terra](https://terra.money/) or [Dydx](https://dydx.exchange/). [Many more](https://cosmos.network/ecosystem) are building on the Cosmos SDK. ## Getting started with the Cosmos SDK diff --git a/docs/learn/intro/02-sdk-app-architecture.md b/docs/learn/intro/02-sdk-app-architecture.md index 6ace65e57abc..1f6d9df78d2d 100644 --- a/docs/learn/intro/02-sdk-app-architecture.md +++ b/docs/learn/intro/02-sdk-app-architecture.md @@ -54,7 +54,7 @@ flowchart LR A -->|"For each T in B: apply(T)"| B ``` -In a blockchain context, the state machine is deterministic. This means that if a node is started at a given state and replays the same sequence of transactions, it will always end up with the same final state. +In a blockchain context, the state machine is [deterministic](https://en.wikipedia.org/wiki/Deterministic_system). This means that if a node is started at a given state and replays the same sequence of transactions, it will always end up with the same final state. The Cosmos SDK gives developers maximum flexibility to define the state of their application, transaction types and state transition functions. The process of building state machines with the Cosmos SDK will be described more in-depth in the following sections. But first, let us see how the state machine is replicated using various consensus engines, such as CometBFT. @@ -117,7 +117,7 @@ Note that **CometBFT only handles transaction bytes**. It has no knowledge of wh Here are the most important messages of the ABCI: -* `CheckTx`: When a transaction is received by CometBFT, it is passed to the application to check if a few basic requirements are met. `CheckTx` is used to protect the mempool of full-nodes against spam transactions. . A special handler called the [`AnteHandler`](../beginner/04-gas-fees.md#antehandler) is used to execute a series of validation steps such as checking for sufficient fees and validating the signatures. If the checks are valid, the transaction is added to the [mempool](https://docs.cometbft.com/v1.0/explanation/core/mempool) and relayed to peer nodes. Note that transactions are not processed (i.e. no modification of the state occurs) with `CheckTx` since they have not been included in a block yet. +* `CheckTx`: When a transaction is received by CometBFT, it is passed to the application to check if a few basic requirements are met. `CheckTx` is used to protect the mempool of full-nodes against spam transactions. A special handler called the [`AnteHandler`](../beginner/04-gas-fees.md#antehandler) is used to execute a series of validation steps such as checking for sufficient fees and validating the signatures. If the checks are valid, the transaction is added to the [mempool](https://docs.cometbft.com/v1.0/explanation/core/mempool) and relayed to peer nodes. Note that transactions are not processed (i.e. no modification of the state occurs) with `CheckTx` since they have not been included in a block yet. * `DeliverTx`: When a [valid block](https://docs.cometbft.com/v1.0/spec/core/data_structures#block) is received by CometBFT, each transaction in the block is passed to the application via `DeliverTx` in order to be processed. It is during this stage that the state transitions occur. The `AnteHandler` executes again, along with the actual [`Msg` service](../../build/building-modules/03-msg-services.md) RPC for each message in the transaction. * `BeginBlock`/`EndBlock`: These messages are executed at the beginning and the end of each block, whether the block contains transactions or not. It is useful to trigger automatic execution of logic. Proceed with caution though, as computationally expensive loops could slow down your blockchain, or even freeze it if the loop is infinite. @@ -136,4 +136,4 @@ If we use the example of Rollkit, a user initiates a transaction, which is then The Interoperability Layer enables communication and interaction between different blockchains. This layer facilitates cross-chain transactions and data sharing, allowing various blockchain networks to interoperate seamlessly. Interoperability is key for building a connected ecosystem of blockchains, enhancing their functionality and reach. -In this case we have separated the layers even further to really illustrate the components that make-up the blockchain architecture and it is important to note that the Cosmos SDK is designed to be interoperable with other blockchains. This is achieved through the use of the Inter-Blockchain Communication (IBC) protocol, which allows different blockchains to communicate and transfer assets between each other. +In this case we have separated the layers even further to really illustrate the components that make-up the blockchain architecture and it is important to note that the Cosmos SDK is designed to be interoperable with other blockchains. This is achieved through the use of the [Inter-Blockchain Communication (IBC) protocol](https://www.ibcprotocol.dev/), which allows different blockchains to communicate and transfer assets between each other. diff --git a/docs/learn/intro/03-sdk-design.md b/docs/learn/intro/03-sdk-design.md index e2edcd4efb02..9ae17b73bb16 100644 --- a/docs/learn/intro/03-sdk-design.md +++ b/docs/learn/intro/03-sdk-design.md @@ -22,7 +22,7 @@ Here is a simplified view of how transactions are handled by an application buil Here is an example of this from `simapp`, the Cosmos SDK demonstration app: ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.50.0-alpha.0/simapp/app.go#L170-L212 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/simapp/app.go#L145-L186 ``` The goal of `baseapp` is to provide a secure interface between the store and the extensible state machine while defining as little about the state machine as possible (staying true to the ABCI). @@ -33,7 +33,7 @@ For more on `baseapp`, please click [here](../advanced/00-baseapp.md). The Cosmos SDK provides a [`multistore`](../advanced/04-store.md#multistore) for persisting state. The multistore allows developers to declare any number of [`KVStores`](../advanced/04-store.md#base-layer-kvstores). These `KVStores` only accept the `[]byte` type as value and therefore any custom structure needs to be marshalled using [a codec](../advanced/05-encoding.md) before being stored. -The multistore abstraction is used to divide the state in distinct compartments, each managed by its own module. For more on the multistore, click [here](../advanced/04-store.md#multistore) +The multistore abstraction is used to divide the state in distinct compartments, each managed by its own module. For more on the multistore, click [here](../advanced/04-store.md#multistore). ## Modules @@ -61,6 +61,6 @@ Cosmos SDK modules are defined in the `x/` folder of the Cosmos SDK. Some core m * `x/auth`: Used to manage accounts and signatures. * `x/bank`: Used to enable tokens and token transfers. -* `x/staking` + `x/slashing`: Used to build Proof-Of-Stake blockchains. +* `x/staking` + `x/slashing`: Used to build Proof-of-Stake blockchains. -In addition to the already existing modules in `x/`, that anyone can use in their app, the Cosmos SDK lets you build your own custom modules. You can check an [example of that in the tutorial](https://tutorials.cosmos.network/). +In addition to the already existing modules in `x/`, which anyone can use in their app, the Cosmos SDK lets you build your own custom modules. You can check an [example of that in the tutorial](https://tutorials.cosmos.network/). diff --git a/docs/learn/learn.md b/docs/learn/learn.md index b8f64821a906..3414fa1a2039 100644 --- a/docs/learn/learn.md +++ b/docs/learn/learn.md @@ -3,8 +3,8 @@ sidebar_position: 0 --- # Learn -* [Introduction](./intro/00-overview.md) - Dive into the fundamentals of Cosmos SDK with an insightful introduction, -laying the groundwork for understanding blockchain development. In this section we provide a High-Level Overview of the SDK, then dive deeper into Core concepts such as Application-Specific Blockchains, Blockchain Architecture, and finally we begin to explore what are the main components of the SDK. +* [Introduction](./intro/00-overview.md) - Dive into the fundamentals of Cosmos SDK with an insightful introduction, +laying the groundwork for understanding blockchain development. In this section, we provide a High-Level Overview of the SDK, then dive deeper into Core concepts such as Application-Specific Blockchains, Blockchain Architecture, and finally, we begin to explore the main components of the SDK. * [Beginner](./beginner/00-app-anatomy.md) - Start your journey with beginner-friendly resources in the Cosmos SDK's "Learn" section, providing a gentle entry point for newcomers to blockchain development. Here we focus on a little more detail, covering the Anatomy of a Cosmos SDK Application, Transaction Lifecycles, Accounts and lastly, Gas and Fees. * [Advanced](./advanced/00-baseapp.md) - Level up your Cosmos SDK expertise with advanced topics, tailored for experienced diff --git a/go.mod b/go.mod index d103e4fbf456..316ed8448cf6 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/mdp/qrterminal/v3 v3.2.0 github.com/muesli/termenv v0.15.2 github.com/prometheus/client_golang v1.20.4 - github.com/prometheus/common v0.59.1 + github.com/prometheus/common v0.60.0 github.com/rs/zerolog v1.33.0 github.com/spf13/cast v1.7.0 github.com/spf13/cobra v1.8.1 diff --git a/go.sum b/go.sum index 1426df122e8d..5aff95150b03 100644 --- a/go.sum +++ b/go.sum @@ -411,8 +411,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/orm/go.mod b/orm/go.mod index 67d3edf261fc..8bd1d5f47d99 100644 --- a/orm/go.mod +++ b/orm/go.mod @@ -50,14 +50,14 @@ require ( github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/linxGnu/grocksdb v1.8.12 // indirect - github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect + github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/onsi/gomega v1.20.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.12.0 // indirect - github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a // indirect - github.com/prometheus/common v0.32.1 // indirect - github.com/prometheus/procfs v0.7.3 // indirect + github.com/prometheus/client_golang v1.20.4 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.60.0 // indirect + github.com/prometheus/procfs v0.15.1 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect diff --git a/orm/go.sum b/orm/go.sum index 911993658638..0635f05e49b4 100644 --- a/orm/go.sum +++ b/orm/go.sum @@ -1,35 +1,3 @@ -cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU= -cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU= -cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY= -cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc= -cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0= -cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To= -cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4= -cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M= -cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc= -cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk= -cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs= -cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc= -cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY= -cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o= -cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE= -cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc= -cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg= -cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc= -cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ= -cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE= -cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk= -cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I= -cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw= -cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA= -cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU= -cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw= -cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos= -cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= -cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs= -cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= @@ -42,32 +10,17 @@ cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/schema v0.3.0 h1:01lcaM4trhzZ1HQTfTV8z6Ma1GziOZ/YmdzBN3F720c= cosmossdk.io/schema v0.3.0/go.mod h1:RDAhxIeNB4bYqAlF4NBJwRrgtnciMcyyg0DOKnhNZQQ= -dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/DataDog/zstd v1.4.5 h1:EndNeuB0l9syBZhut0wns3gV1hL8zX8LIu6ZiVHWLIQ= github.com/DataDog/zstd v1.4.5/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo= -github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= -github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= -github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= -github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= -github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I= github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= -github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= -github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cockroachdb/apd/v3 v3.2.1 h1:U+8j7t0axsIgvQUqthuNm82HIrYXodOV2iWLWtEaIwg= github.com/cockroachdb/apd/v3 v3.2.1/go.mod h1:klXJcjp+FffLTHlhIG69tezTDvdP065naDsHzKhYSqc= github.com/cockroachdb/datadriven v1.0.3-0.20230413201302-be42291fc80f h1:otljaYPt5hWxV3MUfO5dFPFiOXg9CyG5/kCfayTqsJ4= @@ -99,10 +52,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= -github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= -github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= @@ -114,133 +63,58 @@ github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkN github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ= github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= -github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= -github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= -github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= -github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= -github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= -github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= -github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= -github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y= -github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw= -github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4= github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc= github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.0/go.mod h1:Qd/q+1AKNOZr9uGQzbzCmRO6sUih6GTPZv6a1/R87v0= -github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= -github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= -github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= -github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= -github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= -github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= github.com/google/btree v1.1.2 h1:xf4v41cLI2Z6FxbKm+8Bu+m8ifhj15JuZ9sa0jZCMUU= github.com/google/btree v1.1.2/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= -github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI= -github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= -github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= -github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= -github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= -github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI= github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= -github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= -github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= -github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= -github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= -github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.10 h1:oXAz+Vh0PMUvJczoi+flxpnBEPxoER1IaAnU/NMPtT0= github.com/klauspost/compress v1.17.10/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw= github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/linxGnu/grocksdb v1.8.12 h1:1/pCztQUOa3BX/1gR3jSZDoaKFpeHFvQ1XrqZpSvZVo= github.com/linxGnu/grocksdb v1.8.12/go.mod h1:xZCIb5Muw+nhbDK4Y5UJuOrin5MceOuiXkVUR7vp4WY= -github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI= -github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= -github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= -github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= -github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= +github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= @@ -259,52 +133,28 @@ github.com/onsi/gomega v1.20.0/go.mod h1:DtrZpjmvpn2mPm4YWQa0/ALMDj9v4YxLgojwPeR github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4= github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= -github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= -github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= -github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0= -github.com/prometheus/client_golang v1.12.0 h1:C+UIj/QWtmqY13Arb8kwMt5j34/0Z2iKamrJ+ryC0Gg= -github.com/prometheus/client_golang v1.12.0/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY= -github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= -github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a h1:CmF68hwI0XsOQ5UwlBopMi2Ow4Pbg32akc4KIVCOm+Y= -github.com/prometheus/client_model v0.2.1-0.20210607210712-147c58e9608a/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w= -github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= -github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= -github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc= -github.com/prometheus/common v0.32.1 h1:hWIdL3N2HoUx3B8j3YN9mWor0qhY/NlEKZEaXxuIRh4= -github.com/prometheus/common v0.32.1/go.mod h1:vu+V0TpY+O6vW9J44gczi3Ap/oXXR10b+M/gUGO4Hls= -github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= -github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= -github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU= -github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= -github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU= -github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA= +github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= +github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= +github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= +github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/regen-network/gocuke v1.1.1 h1:13D3n5xLbpzA/J2ELHC9jXYq0+XyEr64A3ehjvfmBbE= github.com/regen-network/gocuke v1.1.1/go.mod h1:Nl9EbhLmTzdLqb52fr/Fvf8LcoVuTjjf8FlLmXz1zHo= -github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= -github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= @@ -315,158 +165,53 @@ github.com/tendermint/go-amino v0.16.0 h1:GyhmgQKvqF82e2oZeuMSp9JTN0N09emoSZlb2l github.com/tendermint/go-amino v0.16.0/go.mod h1:TQU0M1i/ImAo+tYpZi73AU3V/dKeCoMC9Sphe2ZwGME= github.com/tidwall/btree v1.7.0 h1:L1fkJH/AuEh5zBnnBbmTwQ5Lt+bRJ5A8EWecslvo9iI= github.com/tidwall/btree v1.7.0/go.mod h1:twD9XRA5jj9VUQGELzDO4HPQTNJsoWWfYEL+EUQ2cKY= -github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= -go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= -go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= -golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= -golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek= -golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY= -golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= -golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= -golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= -golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= -golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= -golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= -golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= -golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs= -golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= -golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= -golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= -golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= -golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= -golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= -golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= -golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/oauth2 v0.0.0-20210514164344-f6687ab2804c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= -golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -474,59 +219,15 @@ golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= -golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= -golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= -golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw= -golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8= -golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= -golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= -golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= @@ -535,74 +236,11 @@ golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8= -google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= -google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= -google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg= -google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI= -google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE= -google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE= -google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM= -google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc= -google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= -google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= -google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= -google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE= -google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= -google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8= -google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc= -google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA= -google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c= -google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U= -google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA= -google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= -google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 h1:wKguEg1hsxI2/L3hUYrpo1RVi48K+uTyzKqprwLXsb8= google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142/go.mod h1:d6be+8HhtEtucleCbxpPW9PA9XwISACu8nvpPqF0BVo= google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f h1:cUMEy+8oS78BWIH9OWazBkzbr090Od9tWBNtZHkOhf0= google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU= -google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= -google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= -google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= -google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= -google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= -google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= -google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60= -google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk= -google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= -google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak= google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E= google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -610,46 +248,26 @@ google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= -google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= -google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= -gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU= gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU= -honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= -honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= -honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw= pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= -rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= -rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= -rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E= sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY= diff --git a/runtime/v2/app.go b/runtime/v2/app.go index b7104f9e4774..caf55b92ce01 100644 --- a/runtime/v2/app.go +++ b/runtime/v2/app.go @@ -5,9 +5,8 @@ import ( "errors" "slices" - gogoproto "github.com/cosmos/gogoproto/proto" - runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/registry" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -43,9 +42,8 @@ type App[T transaction.Tx] struct { amino registry.AminoRegistrar moduleManager *MM[T] - // GRPCMethodsToMessageMap maps gRPC method name to a function that decodes the request - // bytes into a gogoproto.Message, which then can be passed to appmanager. - GRPCMethodsToMessageMap map[string]func() gogoproto.Message + // QueryHandlers defines the query handlers + QueryHandlers map[string]appmodulev2.Handler storeLoader StoreLoader } @@ -120,6 +118,6 @@ func (a *App[T]) GetAppManager() *appmanager.AppManager[T] { return a.AppManager } -func (a *App[T]) GetGPRCMethodsToMessageMap() map[string]func() gogoproto.Message { - return a.GRPCMethodsToMessageMap +func (a *App[T]) GetQueryHandlers() map[string]appmodulev2.Handler { + return a.QueryHandlers } diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index 8510f8a850ea..1bd24cd1e26c 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -65,7 +65,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/zerolog v1.33.0 // indirect diff --git a/runtime/v2/go.sum b/runtime/v2/go.sum index 88152b174ee7..b273f05e2e32 100644 --- a/runtime/v2/go.sum +++ b/runtime/v2/go.sum @@ -202,8 +202,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/runtime/v2/manager.go b/runtime/v2/manager.go index 02df9ac750f3..01b0c93971ab 100644 --- a/runtime/v2/manager.go +++ b/runtime/v2/manager.go @@ -615,46 +615,46 @@ func (m *MM[T]) assertNoForgottenModules( } func registerServices[T transaction.Tx](s appmodulev2.AppModule, app *App[T], registry *protoregistry.Files) error { - c := &configurator{ - grpcQueryDecoders: map[string]func() gogoproto.Message{}, - stfQueryRouter: app.queryRouterBuilder, - stfMsgRouter: app.msgRouterBuilder, - registry: registry, - err: nil, - } - + // case module with services if services, ok := s.(hasServicesV1); ok { + c := &configurator{ + queryHandlers: map[string]appmodulev2.Handler{}, + stfQueryRouter: app.queryRouterBuilder, + stfMsgRouter: app.msgRouterBuilder, + registry: registry, + err: nil, + } if err := services.RegisterServices(c); err != nil { return fmt.Errorf("unable to register services: %w", err) } - } else { - // If module not implement RegisterServices, register msg & query handler. - if module, ok := s.(appmodulev2.HasMsgHandlers); ok { - wrapper := stfRouterWrapper{stfRouter: app.msgRouterBuilder} - module.RegisterMsgHandlers(&wrapper) - if wrapper.error != nil { - return fmt.Errorf("unable to register handlers: %w", wrapper.error) - } - } - if module, ok := s.(appmodulev2.HasQueryHandlers); ok { - wrapper := stfRouterWrapper{stfRouter: app.msgRouterBuilder} - module.RegisterQueryHandlers(&wrapper) - - for path, decoder := range wrapper.decoders { - app.GRPCMethodsToMessageMap[path] = decoder - } + if c.err != nil { + app.logger.Warn("error registering services", "error", c.err) } + // merge maps + for path, decoder := range c.queryHandlers { + app.QueryHandlers[path] = decoder + } } - if c.err != nil { - app.logger.Warn("error registering services", "error", c.err) + // if module implements register msg handlers + if module, ok := s.(appmodulev2.HasMsgHandlers); ok { + wrapper := stfRouterWrapper{stfRouter: app.msgRouterBuilder} + module.RegisterMsgHandlers(&wrapper) + if wrapper.error != nil { + return fmt.Errorf("unable to register handlers: %w", wrapper.error) + } } - // merge maps - for path, decoder := range c.grpcQueryDecoders { - app.GRPCMethodsToMessageMap[path] = decoder + // if module implements register query handlers + if module, ok := s.(appmodulev2.HasQueryHandlers); ok { + wrapper := stfRouterWrapper{stfRouter: app.queryRouterBuilder} + module.RegisterQueryHandlers(&wrapper) + + for path, handler := range wrapper.handlers { + app.QueryHandlers[path] = handler + } } return nil @@ -663,9 +663,7 @@ func registerServices[T transaction.Tx](s appmodulev2.AppModule, app *App[T], re var _ grpc.ServiceRegistrar = (*configurator)(nil) type configurator struct { - // grpcQueryDecoders is required because module expose queries through gRPC - // this provides a way to route to modules using gRPC. - grpcQueryDecoders map[string]func() gogoproto.Message + queryHandlers map[string]appmodulev2.Handler stfQueryRouter *stf.MsgRouterBuilder stfMsgRouter *stf.MsgRouterBuilder @@ -697,28 +695,31 @@ func (c *configurator) RegisterService(sd *grpc.ServiceDesc, ss interface{}) { func (c *configurator) registerQueryHandlers(sd *grpc.ServiceDesc, ss interface{}) error { for _, md := range sd.Methods { // TODO(tip): what if a query is not deterministic? - requestFullName, err := registerMethod(c.stfQueryRouter, sd, md, ss) + + handler, err := grpcHandlerToAppModuleHandler(sd, md, ss) if err != nil { - return fmt.Errorf("unable to register query handler %s.%s: %w", sd.ServiceName, md.MethodName, err) + return fmt.Errorf("unable to make a appmodulev2.HandlerFunc from gRPC handler (%s, %s): %w", sd.ServiceName, md.MethodName, err) } - // register gRPC query method. - typ := gogoproto.MessageType(requestFullName) - if typ == nil { - return fmt.Errorf("unable to find message in gogotype registry: %w", err) - } - decoderFunc := func() gogoproto.Message { - return reflect.New(typ.Elem()).Interface().(gogoproto.Message) + // register to stf query router. + err = c.stfQueryRouter.RegisterHandler(gogoproto.MessageName(handler.MakeMsg()), handler.Func) + if err != nil { + return fmt.Errorf("unable to register handler to stf router (%s, %s): %w", sd.ServiceName, md.MethodName, err) } - methodName := fmt.Sprintf("/%s/%s", sd.ServiceName, md.MethodName) - c.grpcQueryDecoders[methodName] = decoderFunc + + // register query handler using the same mapping used in stf + c.queryHandlers[gogoproto.MessageName(handler.MakeMsg())] = handler } return nil } func (c *configurator) registerMsgHandlers(sd *grpc.ServiceDesc, ss interface{}) error { for _, md := range sd.Methods { - _, err := registerMethod(c.stfMsgRouter, sd, md, ss) + handler, err := grpcHandlerToAppModuleHandler(sd, md, ss) + if err != nil { + return err + } + err = c.stfMsgRouter.RegisterHandler(gogoproto.MessageName(handler.MakeMsg()), handler.Func) if err != nil { return fmt.Errorf("unable to register msg handler %s.%s: %w", sd.ServiceName, md.MethodName, err) } @@ -726,32 +727,27 @@ func (c *configurator) registerMsgHandlers(sd *grpc.ServiceDesc, ss interface{}) return nil } -// requestFullNameFromMethodDesc returns the fully-qualified name of the request message of the provided service's method. -func requestFullNameFromMethodDesc(sd *grpc.ServiceDesc, method grpc.MethodDesc) (protoreflect.FullName, error) { - methodFullName := protoreflect.FullName(fmt.Sprintf("%s.%s", sd.ServiceName, method.MethodName)) - desc, err := gogoproto.HybridResolver.FindDescriptorByName(methodFullName) - if err != nil { - return "", fmt.Errorf("cannot find method descriptor %s", methodFullName) - } - methodDesc, ok := desc.(protoreflect.MethodDescriptor) - if !ok { - return "", fmt.Errorf("invalid method descriptor %s", methodFullName) - } - return methodDesc.Input().FullName(), nil -} - -func registerMethod( - stfRouter *stf.MsgRouterBuilder, +// grpcHandlerToAppModuleHandler converts a gRPC handler into an appmodulev2.HandlerFunc. +func grpcHandlerToAppModuleHandler( sd *grpc.ServiceDesc, md grpc.MethodDesc, ss interface{}, -) (string, error) { - requestName, err := requestFullNameFromMethodDesc(sd, md) +) (appmodulev2.Handler, error) { + requestName, responseName, err := requestFullNameFromMethodDesc(sd, md) if err != nil { - return "", err + return appmodulev2.Handler{}, err } - return string(requestName), stfRouter.RegisterHandler(string(requestName), func( + requestTyp := gogoproto.MessageType(string(requestName)) + if requestTyp == nil { + return appmodulev2.Handler{}, fmt.Errorf("no proto message found for %s", requestName) + } + responseTyp := gogoproto.MessageType(string(responseName)) + if responseTyp == nil { + return appmodulev2.Handler{}, fmt.Errorf("no proto message found for %s", responseName) + } + + handlerFunc := func( ctx context.Context, msg transaction.Msg, ) (resp transaction.Msg, err error) { @@ -760,7 +756,17 @@ func registerMethod( return nil, err } return res.(transaction.Msg), nil - }) + } + + return appmodulev2.Handler{ + Func: handlerFunc, + MakeMsg: func() transaction.Msg { + return reflect.New(requestTyp.Elem()).Interface().(transaction.Msg) + }, + MakeMsgResp: func() transaction.Msg { + return reflect.New(responseTyp.Elem()).Interface().(transaction.Msg) + }, + }, nil } func noopDecoder(_ interface{}) error { return nil } @@ -776,6 +782,20 @@ func messagePassingInterceptor(msg transaction.Msg) grpc.UnaryServerInterceptor } } +// requestFullNameFromMethodDesc returns the fully-qualified name of the request message and response of the provided service's method. +func requestFullNameFromMethodDesc(sd *grpc.ServiceDesc, method grpc.MethodDesc) (protoreflect.FullName, protoreflect.FullName, error) { + methodFullName := protoreflect.FullName(fmt.Sprintf("%s.%s", sd.ServiceName, method.MethodName)) + desc, err := gogoproto.HybridResolver.FindDescriptorByName(methodFullName) + if err != nil { + return "", "", fmt.Errorf("cannot find method descriptor %s", methodFullName) + } + methodDesc, ok := desc.(protoreflect.MethodDescriptor) + if !ok { + return "", "", fmt.Errorf("invalid method descriptor %s", methodFullName) + } + return methodDesc.Input().FullName(), methodDesc.Output().FullName(), nil +} + // defaultMigrationsOrder returns a default migrations order: ascending alphabetical by module name, // except x/auth which will run last, see: // https://github.com/cosmos/cosmos-sdk/issues/10591 @@ -815,7 +835,7 @@ type stfRouterWrapper struct { error error - decoders map[string]func() gogoproto.Message + handlers map[string]appmodulev2.Handler } func (s *stfRouterWrapper) RegisterHandler(handler appmodulev2.Handler) { @@ -831,7 +851,7 @@ func (s *stfRouterWrapper) RegisterHandler(handler appmodulev2.Handler) { // also make the decoder if s.error == nil { - s.decoders = map[string]func() gogoproto.Message{} + s.handlers = map[string]appmodulev2.Handler{} } - s.decoders[requestName] = handler.MakeMsg + s.handlers[requestName] = handler } diff --git a/runtime/v2/module.go b/runtime/v2/module.go index 8e8b7e0ce832..a95e38f96ea5 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -127,13 +127,13 @@ func ProvideAppBuilder[T transaction.Tx]( msgRouterBuilder := stf.NewMsgRouterBuilder() app := &App[T]{ - storeKeys: nil, - interfaceRegistrar: interfaceRegistrar, - amino: amino, - msgRouterBuilder: msgRouterBuilder, - queryRouterBuilder: stf.NewMsgRouterBuilder(), // TODO dedicated query router - GRPCMethodsToMessageMap: map[string]func() proto.Message{}, - storeLoader: DefaultStoreLoader, + storeKeys: nil, + interfaceRegistrar: interfaceRegistrar, + amino: amino, + msgRouterBuilder: msgRouterBuilder, + queryRouterBuilder: stf.NewMsgRouterBuilder(), // TODO dedicated query router + QueryHandlers: map[string]appmodulev2.Handler{}, + storeLoader: DefaultStoreLoader, } appBuilder := &AppBuilder[T]{app: app} diff --git a/server/cmt_cmds.go b/server/cmt_cmds.go index e4c84364dd5a..d511cc105696 100644 --- a/server/cmt_cmds.go +++ b/server/cmt_cmds.go @@ -368,7 +368,7 @@ func BootstrapStateCmd[T types.Application](appCreator types.AppCreator[T]) *cob Use: "bootstrap-state", Short: "Bootstrap CometBFT state at an arbitrary block height using a light client", Args: cobra.NoArgs, - Example: fmt.Sprintf("%s bootstrap-state --height 1000000", version.AppName), + Example: "bootstrap-state --height 1000000", RunE: func(cmd *cobra.Command, args []string) error { serverCtx := GetServerContextFromCmd(cmd) logger := log.NewLogger(cmd.OutOrStdout()) diff --git a/server/v2/api/grpc/server.go b/server/v2/api/grpc/server.go index 170343fd512c..7b70363f6f16 100644 --- a/server/v2/api/grpc/server.go +++ b/server/v2/api/grpc/server.go @@ -9,14 +9,18 @@ import ( "net" "slices" "strconv" + "strings" + "sync" - "github.com/cosmos/gogoproto/proto" + gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/pflag" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + "google.golang.org/protobuf/reflect/protoreflect" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/transaction" "cosmossdk.io/log" serverv2 "cosmossdk.io/server/v2" @@ -53,7 +57,7 @@ func (s *Server[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logger log.L return fmt.Errorf("failed to unmarshal config: %w", err) } } - methodsMap := appI.GetGPRCMethodsToMessageMap() + methodsMap := appI.GetQueryHandlers() grpcSrv := grpc.NewServer( grpc.ForceServerCodec(newProtoCodec(appI.InterfaceRegistry()).GRPCCodec()), @@ -80,21 +84,42 @@ func (s *Server[T]) StartCmdFlags() *pflag.FlagSet { return flags } -func makeUnknownServiceHandler(messageMap map[string]func() proto.Message, querier interface { - Query(ctx context.Context, version uint64, msg proto.Message) (proto.Message, error) +func makeUnknownServiceHandler(handlers map[string]appmodulev2.Handler, querier interface { + Query(ctx context.Context, version uint64, msg gogoproto.Message) (gogoproto.Message, error) }, ) grpc.StreamHandler { + getRegistry := sync.OnceValues(gogoproto.MergedRegistry) + return func(srv any, stream grpc.ServerStream) error { method, ok := grpc.MethodFromServerStream(stream) if !ok { return status.Error(codes.InvalidArgument, "unable to get method") } - makeMsg, exists := messageMap[method] + // if this fails we cannot serve queries anymore... + registry, err := getRegistry() + if err != nil { + return fmt.Errorf("failed to get registry: %w", err) + } + + method = strings.TrimPrefix(method, "/") + fullName := protoreflect.FullName(strings.ReplaceAll(method, "/", ".")) + // get descriptor from the invoke method + desc, err := registry.FindDescriptorByName(fullName) + if err != nil { + return fmt.Errorf("failed to find descriptor %s: %w", method, err) + } + md, ok := desc.(protoreflect.MethodDescriptor) + if !ok { + return fmt.Errorf("%s is not a method", method) + } + // find handler + handler, exists := handlers[string(md.Input().FullName())] if !exists { return status.Errorf(codes.Unimplemented, "gRPC method %s is not handled", method) } + for { - req := makeMsg() + req := handler.MakeMsg() err := stream.RecvMsg(req) if err != nil { if errors.Is(err, io.EOF) { diff --git a/server/v2/cometbft/abci.go b/server/v2/cometbft/abci.go index 02966c874770..cbcf387168a2 100644 --- a/server/v2/cometbft/abci.go +++ b/server/v2/cometbft/abci.go @@ -5,13 +5,18 @@ import ( "crypto/sha256" "errors" "fmt" + "strings" + "sync" "sync/atomic" abci "github.com/cometbft/cometbft/abci/types" abciproto "github.com/cometbft/cometbft/api/cometbft/abci/v1" gogoproto "github.com/cosmos/gogoproto/proto" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/reflect/protoregistry" "cosmossdk.io/collections" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/comet" corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/event" @@ -20,6 +25,7 @@ import ( "cosmossdk.io/core/transaction" errorsmod "cosmossdk.io/errors/v2" "cosmossdk.io/log" + "cosmossdk.io/schema/appdata" "cosmossdk.io/server/v2/appmanager" "cosmossdk.io/server/v2/cometbft/client/grpc/cmtservice" "cosmossdk.io/server/v2/cometbft/handlers" @@ -40,6 +46,7 @@ type Consensus[T transaction.Tx] struct { txCodec transaction.Codec[T] store types.Store streaming streaming.Manager + listener *appdata.Listener snapshotManager *snapshots.Manager mempool mempool.Mempool[T] @@ -57,11 +64,13 @@ type Consensus[T transaction.Tx] struct { processProposalHandler handlers.ProcessHandler[T] verifyVoteExt handlers.VerifyVoteExtensionhandler extendVote handlers.ExtendVoteHandler + checkTxHandler handlers.CheckTxHandler[T] addrPeerFilter types.PeerFilter // filter peers by address and port idPeerFilter types.PeerFilter // filter peers by node ID - grpcMethodsMap map[string]func() transaction.Msg // maps gRPC method to message creator func + queryHandlersMap map[string]appmodulev2.Handler + getProtoRegistry func() (*protoregistry.Files, error) } func NewConsensus[T transaction.Tx]( @@ -70,7 +79,7 @@ func NewConsensus[T transaction.Tx]( app *appmanager.AppManager[T], mp mempool.Mempool[T], indexedEvents map[string]struct{}, - gRPCMethodsMap map[string]func() transaction.Msg, + queryHandlersMap map[string]appmodulev2.Handler, store types.Store, cfg Config, txCodec transaction.Codec[T], @@ -79,7 +88,6 @@ func NewConsensus[T transaction.Tx]( return &Consensus[T]{ appName: appName, version: getCometBFTServerVersion(), - grpcMethodsMap: gRPCMethodsMap, app: app, cfg: cfg, store: store, @@ -96,6 +104,8 @@ func NewConsensus[T transaction.Tx]( chainID: chainId, indexedEvents: indexedEvents, initialHeight: 0, + queryHandlersMap: queryHandlersMap, + getProtoRegistry: sync.OnceValues(func() (*protoregistry.Files, error) { return gogoproto.MergedRegistry() }), } } @@ -104,6 +114,11 @@ func (c *Consensus[T]) SetStreamingManager(sm streaming.Manager) { c.streaming = sm } +// SetListener sets the listener for the consensus module. +func (c *Consensus[T]) SetListener(l *appdata.Listener) { + c.listener = l +} + // RegisterSnapshotExtensions registers the given extensions with the consensus module's snapshot manager. // It allows additional snapshotter implementations to be used for creating and restoring snapshots. func (c *Consensus[T]) RegisterSnapshotExtensions(extensions ...snapshots.ExtensionSnapshotter) error { @@ -122,31 +137,35 @@ func (c *Consensus[T]) CheckTx(ctx context.Context, req *abciproto.CheckTxReques return nil, err } - resp, err := c.app.ValidateTx(ctx, decodedTx) - // we do not want to return a cometbft error, but a check tx response with the error - if err != nil && !errors.Is(err, resp.Error) { - return nil, err - } + if c.checkTxHandler == nil { + resp, err := c.app.ValidateTx(ctx, decodedTx) + // we do not want to return a cometbft error, but a check tx response with the error + if err != nil && !errors.Is(err, resp.Error) { + return nil, err + } - events, err := intoABCIEvents(resp.Events, c.indexedEvents) - if err != nil { - return nil, err - } + events, err := intoABCIEvents(resp.Events, c.indexedEvents) + if err != nil { + return nil, err + } - cometResp := &abciproto.CheckTxResponse{ - Code: 0, - GasWanted: uint64ToInt64(resp.GasWanted), - GasUsed: uint64ToInt64(resp.GasUsed), - Events: events, - } - if resp.Error != nil { - space, code, log := errorsmod.ABCIInfo(resp.Error, c.cfg.AppTomlConfig.Trace) - cometResp.Code = code - cometResp.Codespace = space - cometResp.Log = log + cometResp := &abciproto.CheckTxResponse{ + Code: 0, + GasWanted: uint64ToInt64(resp.GasWanted), + GasUsed: uint64ToInt64(resp.GasUsed), + Events: events, + } + if resp.Error != nil { + space, code, log := errorsmod.ABCIInfo(resp.Error, c.cfg.AppTomlConfig.Trace) + cometResp.Code = code + cometResp.Codespace = space + cometResp.Log = log + } + + return cometResp, nil } - return cometResp, nil + return c.checkTxHandler(c.app.ValidateTx) } // Info implements types.Application. @@ -191,23 +210,9 @@ func (c *Consensus[T]) Info(ctx context.Context, _ *abciproto.InfoRequest) (*abc // Query implements types.Application. // It is called by cometbft to query application state. func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) (resp *abciproto.QueryResponse, err error) { - // check if it's a gRPC method - makeGRPCRequest, isGRPC := c.grpcMethodsMap[req.Path] + resp, isGRPC, err := c.maybeRunGRPCQuery(ctx, req) if isGRPC { - protoRequest := makeGRPCRequest() - err = gogoproto.Unmarshal(req.Data, protoRequest) // TODO: use codec - if err != nil { - return nil, fmt.Errorf("unable to decode gRPC request with path %s from ABCI.Query: %w", req.Path, err) - } - res, err := c.app.Query(ctx, uint64(req.Height), protoRequest) - if err != nil { - resp := QueryResult(err, c.cfg.AppTomlConfig.Trace) - resp.Height = req.Height - return resp, err - - } - - return queryResponse(res, req.Height) + return resp, err } // this error most probably means that we can't handle it with a proto message, so @@ -238,6 +243,50 @@ func (c *Consensus[T]) Query(ctx context.Context, req *abciproto.QueryRequest) ( return resp, nil } +func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryRequest) (resp *abciproto.QueryResponse, isGRPC bool, err error) { + // if this fails then we cannot serve queries anymore + registry, err := c.getProtoRegistry() + if err != nil { + return nil, false, err + } + + path := strings.TrimPrefix(req.Path, "/") + pathFullName := protoreflect.FullName(strings.ReplaceAll(path, "/", ".")) + + // in order to check if it's a gRPC query we ensure that there's a descriptor + // for the path, if such descriptor exists, and it is a method descriptor + // then we assume this is a gRPC query. + desc, err := registry.FindDescriptorByName(pathFullName) + if err != nil { + return nil, false, err + } + + md, isGRPC := desc.(protoreflect.MethodDescriptor) + if !isGRPC { + return nil, false, nil + } + + handler, found := c.queryHandlersMap[string(md.Input().FullName())] + if !found { + return nil, true, fmt.Errorf("no query handler found for %s", req.Path) + } + protoRequest := handler.MakeMsg() + err = gogoproto.Unmarshal(req.Data, protoRequest) // TODO: use codec + if err != nil { + return nil, true, fmt.Errorf("unable to decode gRPC request with path %s from ABCI.Query: %w", req.Path, err) + } + res, err := c.app.Query(ctx, uint64(req.Height), protoRequest) + if err != nil { + resp := QueryResult(err, c.cfg.AppTomlConfig.Trace) + resp.Height = req.Height + return resp, true, err + + } + + resp, err = queryResponse(res, req.Height) + return resp, isGRPC, err +} + // InitChain implements types.Application. func (c *Consensus[T]) InitChain(ctx context.Context, req *abciproto.InitChainRequest) (*abciproto.InitChainResponse, error) { c.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId) diff --git a/server/v2/cometbft/go.mod b/server/v2/cometbft/go.mod index 5670b3e108e2..e92a3221ada5 100644 --- a/server/v2/cometbft/go.mod +++ b/server/v2/cometbft/go.mod @@ -22,6 +22,7 @@ require ( cosmossdk.io/core v1.0.0-alpha.4 cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 cosmossdk.io/log v1.4.1 + cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 cosmossdk.io/server/v2 v2.0.0-00010101000000-000000000000 cosmossdk.io/server/v2/appmanager v0.0.0-20240802110823-cffeedff643d cosmossdk.io/server/v2/stf v0.0.0-20240708142107-25e99c54bac1 @@ -35,6 +36,7 @@ require ( github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 github.com/stretchr/testify v1.9.0 + google.golang.org/protobuf v1.34.2 sigs.k8s.io/yaml v1.4.0 ) @@ -45,7 +47,6 @@ require ( cosmossdk.io/depinject v1.0.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/math v1.3.0 // indirect - cosmossdk.io/schema v0.3.1-0.20240930054013-7c6e0388a3f9 // indirect cosmossdk.io/store v1.1.1-0.20240418092142-896cdf1971bc // indirect cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect @@ -141,7 +142,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect @@ -179,7 +180,6 @@ require ( google.golang.org/genproto/googleapis/api v0.0.0-20240814211410-ddb44dafa142 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240930140551-af27646dc61f // indirect google.golang.org/grpc v1.67.1 // indirect - google.golang.org/protobuf v1.34.2 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.5.1 // indirect diff --git a/server/v2/cometbft/go.sum b/server/v2/cometbft/go.sum index 00a9863eee52..ea29392600d8 100644 --- a/server/v2/cometbft/go.sum +++ b/server/v2/cometbft/go.sum @@ -418,8 +418,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/server/v2/cometbft/handlers/handlers.go b/server/v2/cometbft/handlers/handlers.go index 9008490f6a44..015594f469f7 100644 --- a/server/v2/cometbft/handlers/handlers.go +++ b/server/v2/cometbft/handlers/handlers.go @@ -5,6 +5,7 @@ import ( abci "github.com/cometbft/cometbft/api/cometbft/abci/v1" + "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" ) @@ -27,4 +28,7 @@ type ( // It takes a context, a store reader map, and a request to extend a vote. // It returns a response to extend the vote and an error if any. ExtendVoteHandler func(context.Context, store.ReaderMap, *abci.ExtendVoteRequest) (*abci.ExtendVoteResponse, error) + + // CheckTxHandler is a function type that handles the execution of a transaction. + CheckTxHandler[T transaction.Tx] func(func(ctx context.Context, tx T) (server.TxResult, error)) (*abci.CheckTxResponse, error) ) diff --git a/server/v2/cometbft/options.go b/server/v2/cometbft/options.go index 0f5091da70a0..d5aa4872fff2 100644 --- a/server/v2/cometbft/options.go +++ b/server/v2/cometbft/options.go @@ -18,6 +18,7 @@ type keyGenF = func() (cmtcrypto.PrivKey, error) type ServerOptions[T transaction.Tx] struct { PrepareProposalHandler handlers.PrepareHandler[T] ProcessProposalHandler handlers.ProcessHandler[T] + CheckTxHandler handlers.CheckTxHandler[T] VerifyVoteExtensionHandler handlers.VerifyVoteExtensionhandler ExtendVoteHandler handlers.ExtendVoteHandler KeygenF keyGenF @@ -35,6 +36,7 @@ func DefaultServerOptions[T transaction.Tx]() ServerOptions[T] { return ServerOptions[T]{ PrepareProposalHandler: handlers.NoOpPrepareProposal[T](), ProcessProposalHandler: handlers.NoOpProcessProposal[T](), + CheckTxHandler: nil, VerifyVoteExtensionHandler: handlers.NoOpVerifyVoteExtensionHandler(), ExtendVoteHandler: handlers.NoOpExtendVote(), Mempool: func(cfg map[string]any) mempool.Mempool[T] { return mempool.NoOpMempool[T]{} }, diff --git a/server/v2/cometbft/server.go b/server/v2/cometbft/server.go index 21b6d59ddc72..b15f5695cf94 100644 --- a/server/v2/cometbft/server.go +++ b/server/v2/cometbft/server.go @@ -105,7 +105,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg appI.GetAppManager(), s.serverOptions.Mempool(cfg), indexEvents, - appI.GetGPRCMethodsToMessageMap(), + appI.GetQueryHandlers(), store, s.config, s.initTxCodec, @@ -113,6 +113,7 @@ func (s *CometBFTServer[T]) Init(appI serverv2.AppI[T], cfg map[string]any, logg ) consensus.prepareProposalHandler = s.serverOptions.PrepareProposalHandler consensus.processProposalHandler = s.serverOptions.ProcessProposalHandler + consensus.checkTxHandler = s.serverOptions.CheckTxHandler consensus.verifyVoteExt = s.serverOptions.VerifyVoteExtensionHandler consensus.extendVote = s.serverOptions.ExtendVoteHandler consensus.addrPeerFilter = s.serverOptions.AddrPeerFilter diff --git a/server/v2/cometbft/streaming.go b/server/v2/cometbft/streaming.go index 2ccb33dffb99..65f52a002af1 100644 --- a/server/v2/cometbft/streaming.go +++ b/server/v2/cometbft/streaming.go @@ -7,6 +7,7 @@ import ( "cosmossdk.io/core/server" "cosmossdk.io/core/store" errorsmod "cosmossdk.io/errors/v2" + "cosmossdk.io/schema/appdata" "cosmossdk.io/server/v2/streaming" ) @@ -57,6 +58,55 @@ func (c *Consensus[T]) streamDeliverBlockChanges( c.logger.Error("ListenStateChanges listening hook failed", "height", height, "err", err) } } + + if c.listener == nil { + return nil + } + // stream the StartBlockData to the listener. + if c.listener.StartBlock != nil { + if err := c.listener.StartBlock(appdata.StartBlockData{ + Height: uint64(height), + HeaderBytes: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + HeaderJSON: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + }); err != nil { + return err + } + } + // stream the TxData to the listener. + if c.listener.OnTx != nil { + for i, tx := range txs { + if err := c.listener.OnTx(appdata.TxData{ + TxIndex: int32(i), + Bytes: func() ([]byte, error) { return tx, nil }, + JSON: nil, // TODO: https://github.com/cosmos/cosmos-sdk/issues/22009 + }); err != nil { + return err + } + } + } + // stream the EventData to the listener. + if c.listener.OnEvent != nil { + if err := c.listener.OnEvent(appdata.EventData{Events: events}); err != nil { + return err + } + } + // stream the KVPairData to the listener. + if c.listener.OnKVPair != nil { + if err := c.listener.OnKVPair(appdata.KVPairData{Updates: stateChanges}); err != nil { + return err + } + } + // stream the CommitData to the listener. + if c.listener.Commit != nil { + if completionCallback, err := c.listener.Commit(appdata.CommitData{}); err != nil { + return err + } else if completionCallback != nil { + if err := completionCallback(); err != nil { + return err + } + } + } + return nil } diff --git a/server/v2/go.mod b/server/v2/go.mod index 3885246d5b48..220989a6186e 100644 --- a/server/v2/go.mod +++ b/server/v2/go.mod @@ -13,7 +13,7 @@ replace ( require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.3 + cosmossdk.io/core v1.0.0-alpha.4 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/log v1.4.1 cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000 @@ -29,7 +29,7 @@ require ( github.com/mitchellh/mapstructure v1.5.0 github.com/pelletier/go-toml/v2 v2.2.2 github.com/prometheus/client_golang v1.20.4 - github.com/prometheus/common v0.59.1 + github.com/prometheus/common v0.60.0 github.com/rs/zerolog v1.33.0 github.com/spf13/cobra v1.8.1 github.com/spf13/pflag v1.0.5 diff --git a/server/v2/go.sum b/server/v2/go.sum index 4406baf611d3..842232d93dbb 100644 --- a/server/v2/go.sum +++ b/server/v2/go.sum @@ -1,7 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= -cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= +cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/errors/v2 v2.0.0-20240731132947-df72853b3ca5 h1:IQNdY2kB+k+1OM2DvqFG1+UgeU1JzZrWtwuWzI3ZfwA= @@ -268,8 +268,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/server/v2/server_test.go b/server/v2/server_test.go index e84bcd598890..97afa40fdaa9 100644 --- a/server/v2/server_test.go +++ b/server/v2/server_test.go @@ -11,6 +11,7 @@ import ( "github.com/spf13/viper" "github.com/stretchr/testify/require" + appmodulev2 "cosmossdk.io/core/appmodule/v2" coreserver "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -35,8 +36,8 @@ type mockApp[T transaction.Tx] struct { serverv2.AppI[T] } -func (*mockApp[T]) GetGPRCMethodsToMessageMap() map[string]func() gogoproto.Message { - return map[string]func() gogoproto.Message{} +func (*mockApp[T]) GetQueryHandlers() map[string]appmodulev2.Handler { + return map[string]appmodulev2.Handler{} } func (*mockApp[T]) GetAppManager() *appmanager.AppManager[T] { diff --git a/server/v2/stf/stf.go b/server/v2/stf/stf.go index 0dffe561dc98..f665aaf3c6e9 100644 --- a/server/v2/stf/stf.go +++ b/server/v2/stf/stf.go @@ -123,7 +123,6 @@ func (s STF[T]) DeliverBlock( // reset events exCtx.events = make([]event.Event, 0) - // begin block var beginBlockEvents []event.Event if !block.IsGenesis { @@ -147,7 +146,7 @@ func (s STF[T]) DeliverBlock( if err = isCtxCancelled(ctx); err != nil { return nil, nil, err } - txResults[i] = s.deliverTx(exCtx, newState, txBytes, transaction.ExecModeFinalize, hi) + txResults[i] = s.deliverTx(exCtx, newState, txBytes, transaction.ExecModeFinalize, hi, int32(i+1)) } // reset events exCtx.events = make([]event.Event, 0) @@ -173,6 +172,7 @@ func (s STF[T]) deliverTx( tx T, execMode transaction.ExecMode, hi header.Info, + txIndex int32, ) server.TxResult { // recover in the case of a panic var recoveryError error @@ -195,17 +195,32 @@ func (s STF[T]) deliverTx( Error: recoveryError, } } - validateGas, validationEvents, err := s.validateTx(ctx, state, gasLimit, tx, execMode) if err != nil { return server.TxResult{ Error: err, } } + events := make([]event.Event, 0) + // set the event indexes, set MsgIndex to 0 in validation events + for i, e := range validationEvents { + e.BlockStage = appdata.TxProcessingStage + e.TxIndex = txIndex + e.MsgIndex = 0 + e.EventIndex = int32(i + 1) + events = append(events, e) + } execResp, execGas, execEvents, err := s.execTx(ctx, state, gasLimit-validateGas, tx, execMode, hi) + // set the TxIndex in the exec events + for _, e := range execEvents { + e.BlockStage = appdata.TxProcessingStage + e.TxIndex = txIndex + events = append(events, e) + } + return server.TxResult{ - Events: append(validationEvents, execEvents...), + Events: events, GasUsed: execGas + validateGas, GasWanted: gasLimit, Resp: execResp, @@ -271,6 +286,12 @@ func (s STF[T]) execTx( if applyErr != nil { return nil, 0, nil, applyErr } + // set the event indexes, set MsgIndex to -1 in post tx events + for i := range postTxCtx.events { + postTxCtx.events[i].EventIndex = int32(i + 1) + postTxCtx.events[i].MsgIndex = -1 + } + return nil, gasUsed, postTxCtx.events, txErr } // tx execution went fine, now we use the same state to run the post tx exec handler, @@ -290,6 +311,11 @@ func (s STF[T]) execTx( if applyErr != nil { return nil, 0, nil, applyErr } + // set the event indexes, set MsgIndex to -1 in post tx events + for i := range postTxCtx.events { + postTxCtx.events[i].EventIndex = int32(i + 1) + postTxCtx.events[i].MsgIndex = -1 + } return msgsResp, gasUsed, append(runTxMsgsEvents, postTxCtx.events...), nil } @@ -316,17 +342,24 @@ func (s STF[T]) runTxMsgs( execCtx := s.makeContext(ctx, RuntimeIdentity, state, execMode) execCtx.setHeaderInfo(hi) execCtx.setGasLimit(gasLimit) + events := make([]event.Event, 0) for i, msg := range msgs { execCtx.sender = txSenders[i] + execCtx.events = make([]event.Event, 0) // reset events resp, err := s.msgRouter.Invoke(execCtx, msg) if err != nil { return nil, 0, nil, err // do not wrap the error or we lose the original error type } msgResps[i] = resp + for j, e := range execCtx.events { + e.MsgIndex = int32(i + 1) + e.EventIndex = int32(j + 1) + events = append(events, e) + } } consumed := execCtx.meter.Limit() - execCtx.meter.Remaining() - return msgResps, consumed, execCtx.events, nil + return msgResps, consumed, events, nil } // preBlock executes the pre block logic. @@ -341,6 +374,7 @@ func (s STF[T]) preBlock( for i := range ctx.events { ctx.events[i].BlockStage = appdata.PreBlockStage + ctx.events[i].EventIndex = int32(i + 1) } return ctx.events, nil @@ -357,6 +391,7 @@ func (s STF[T]) beginBlock( for i := range ctx.events { ctx.events[i].BlockStage = appdata.BeginBlockStage + ctx.events[i].EventIndex = int32(i + 1) } return ctx.events, nil @@ -370,30 +405,30 @@ func (s STF[T]) endBlock( if err != nil { return nil, nil, err } - - events, valsetUpdates, err := s.validatorUpdates(ctx) + events := ctx.events + ctx.events = make([]event.Event, 0) // reset events + valsetUpdates, err := s.validatorUpdates(ctx) if err != nil { return nil, nil, err } - - ctx.events = append(ctx.events, events...) - - for i := range ctx.events { - ctx.events[i].BlockStage = appdata.EndBlockStage + events = append(events, ctx.events...) + for i := range events { + events[i].BlockStage = appdata.EndBlockStage + events[i].EventIndex = int32(i + 1) } - return ctx.events, valsetUpdates, nil + return events, valsetUpdates, nil } // validatorUpdates returns the validator updates for the current block. It is called by endBlock after the endblock execution has concluded func (s STF[T]) validatorUpdates( ctx *executionContext, -) ([]event.Event, []appmodulev2.ValidatorUpdate, error) { +) ([]appmodulev2.ValidatorUpdate, error) { valSetUpdates, err := s.doValidatorUpdate(ctx) if err != nil { - return nil, nil, err + return nil, err } - return ctx.events, valSetUpdates, nil + return valSetUpdates, nil } // Simulate simulates the execution of a tx on the provided state. @@ -408,7 +443,7 @@ func (s STF[T]) Simulate( if err != nil { return server.TxResult{}, nil } - txr := s.deliverTx(ctx, simulationState, tx, internal.ExecModeSimulate, hi) + txr := s.deliverTx(ctx, simulationState, tx, internal.ExecModeSimulate, hi, 0) return txr, simulationState } diff --git a/server/v2/stf/stf_test.go b/server/v2/stf/stf_test.go index bb2cab62189d..b4c84a62ff9a 100644 --- a/server/v2/stf/stf_test.go +++ b/server/v2/stf/stf_test.go @@ -11,15 +11,19 @@ import ( gogotypes "github.com/cosmos/gogoproto/types" appmodulev2 "cosmossdk.io/core/appmodule/v2" + "cosmossdk.io/core/event" coregas "cosmossdk.io/core/gas" "cosmossdk.io/core/server" "cosmossdk.io/core/store" "cosmossdk.io/core/transaction" + "cosmossdk.io/schema/appdata" "cosmossdk.io/server/v2/stf/branch" "cosmossdk.io/server/v2/stf/gas" "cosmossdk.io/server/v2/stf/mock" ) +const senderAddr = "sender" + func addMsgHandlerToSTF[T any, PT interface { *T transaction.Msg @@ -60,7 +64,7 @@ func addMsgHandlerToSTF[T any, PT interface { func TestSTF(t *testing.T) { state := mock.DB() mockTx := mock.Tx{ - Sender: []byte("sender"), + Sender: []byte(senderAddr), Msg: &gogotypes.BoolValue{Value: true}, GasLimit: 100_000, } @@ -68,22 +72,48 @@ func TestSTF(t *testing.T) { sum := sha256.Sum256([]byte("test-hash")) s := &STF[mock.Tx]{ - doPreBlock: func(ctx context.Context, txs []mock.Tx) error { return nil }, + doPreBlock: func(ctx context.Context, txs []mock.Tx) error { + ctx.(*executionContext).events = append(ctx.(*executionContext).events, event.NewEvent("pre-block")) + return nil + }, doBeginBlock: func(ctx context.Context) error { kvSet(t, ctx, "begin-block") + ctx.(*executionContext).events = append(ctx.(*executionContext).events, event.NewEvent("begin-block")) return nil }, doEndBlock: func(ctx context.Context) error { kvSet(t, ctx, "end-block") + ctx.(*executionContext).events = append(ctx.(*executionContext).events, event.NewEvent("end-block")) return nil }, - doValidatorUpdate: func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { return nil, nil }, + doValidatorUpdate: func(ctx context.Context) ([]appmodulev2.ValidatorUpdate, error) { + ctx.(*executionContext).events = append(ctx.(*executionContext).events, event.NewEvent("validator-update")) + return nil, nil + }, doTxValidation: func(ctx context.Context, tx mock.Tx) error { kvSet(t, ctx, "validate") + ctx.(*executionContext).events = append( + ctx.(*executionContext).events, + event.NewEvent("validate-tx", event.NewAttribute(senderAddr, string(tx.Sender))), + event.NewEvent( + "validate-tx", + event.NewAttribute(senderAddr, string(tx.Sender)), + event.NewAttribute("index", "2"), + ), + ) return nil }, postTxExec: func(ctx context.Context, tx mock.Tx, success bool) error { kvSet(t, ctx, "post-tx-exec") + ctx.(*executionContext).events = append( + ctx.(*executionContext).events, + event.NewEvent("post-tx-exec", event.NewAttribute(senderAddr, string(tx.Sender))), + event.NewEvent( + "post-tx-exec", + event.NewAttribute(senderAddr, string(tx.Sender)), + event.NewAttribute("index", "2"), + ), + ) return nil }, branchFn: branch.DefaultNewWriterMap, @@ -93,6 +123,15 @@ func TestSTF(t *testing.T) { addMsgHandlerToSTF(t, s, func(ctx context.Context, msg *gogotypes.BoolValue) (*gogotypes.BoolValue, error) { kvSet(t, ctx, "exec") + ctx.(*executionContext).events = append( + ctx.(*executionContext).events, + event.NewEvent("handle-msg", event.NewAttribute("msg", msg.String())), + event.NewEvent( + "handle-msg", + event.NewAttribute("msg", msg.String()), + event.NewAttribute("index", "2"), + ), + ) return nil, nil }) @@ -135,13 +174,124 @@ func TestSTF(t *testing.T) { if txResult.GasWanted != mockTx.GasLimit { t.Errorf("Expected GasWanted to be %d, got %d", mockTx.GasLimit, txResult.GasWanted) } + + // Check PreBlockEvents + preBlockEvents := result.PreBlockEvents + if len(preBlockEvents) != 1 { + t.Fatalf("Expected 1 PreBlockEvent, got %d", len(preBlockEvents)) + } + if preBlockEvents[0].Type != "pre-block" { + t.Errorf("Expected PreBlockEvent Type 'pre-block', got %s", preBlockEvents[0].Type) + } + if preBlockEvents[0].BlockStage != appdata.PreBlockStage { + t.Errorf("Expected PreBlockStage %d, got %d", appdata.PreBlockStage, preBlockEvents[0].BlockStage) + } + if preBlockEvents[0].EventIndex != 1 { + t.Errorf("Expected PreBlockEventIndex 1, got %d", preBlockEvents[0].EventIndex) + } + // Check BeginBlockEvents + beginBlockEvents := result.BeginBlockEvents + if len(beginBlockEvents) != 1 { + t.Fatalf("Expected 1 BeginBlockEvent, got %d", len(beginBlockEvents)) + } + if beginBlockEvents[0].Type != "begin-block" { + t.Errorf("Expected BeginBlockEvent Type 'begin-block', got %s", beginBlockEvents[0].Type) + } + if beginBlockEvents[0].BlockStage != appdata.BeginBlockStage { + t.Errorf("Expected BeginBlockStage %d, got %d", appdata.BeginBlockStage, beginBlockEvents[0].BlockStage) + } + if beginBlockEvents[0].EventIndex != 1 { + t.Errorf("Expected BeginBlockEventIndex 1, got %d", beginBlockEvents[0].EventIndex) + } + // Check EndBlockEvents + endBlockEvents := result.EndBlockEvents + if len(endBlockEvents) != 2 { + t.Fatalf("Expected 2 EndBlockEvents, got %d", len(endBlockEvents)) + } + if endBlockEvents[0].Type != "end-block" { + t.Errorf("Expected EndBlockEvent Type 'end-block', got %s", endBlockEvents[0].Type) + } + if endBlockEvents[1].Type != "validator-update" { + t.Errorf("Expected EndBlockEvent Type 'validator-update', got %s", endBlockEvents[1].Type) + } + if endBlockEvents[1].BlockStage != appdata.EndBlockStage { + t.Errorf("Expected EndBlockStage %d, got %d", appdata.EndBlockStage, endBlockEvents[1].BlockStage) + } + if endBlockEvents[0].EventIndex != 1 { + t.Errorf("Expected EndBlockEventIndex 1, got %d", endBlockEvents[0].EventIndex) + } + if endBlockEvents[1].EventIndex != 2 { + t.Errorf("Expected EndBlockEventIndex 2, got %d", endBlockEvents[1].EventIndex) + } + // check TxEvents + events := txResult.Events + if len(events) != 6 { + t.Fatalf("Expected 6 TxEvents, got %d", len(events)) + } + for i, event := range events { + if event.BlockStage != appdata.TxProcessingStage { + t.Errorf("Expected BlockStage %d, got %d", appdata.TxProcessingStage, event.BlockStage) + } + if event.TxIndex != 1 { + t.Errorf("Expected TxIndex 1, got %d", event.TxIndex) + } + if event.EventIndex != int32(i%2+1) { + t.Errorf("Expected EventIndex %d, got %d", i%2+1, event.EventIndex) + } + + attrs, err := event.Attributes() + if err != nil { + t.Fatalf("Error getting event attributes: %v", err) + } + if len(attrs) < 1 || len(attrs) > 2 { + t.Errorf("Expected 1 or 2 attributes, got %d", len(attrs)) + } + + if len(attrs) == 2 { + if attrs[1].Key != "index" || attrs[1].Value != "2" { + t.Errorf("Expected attribute key 'index' and value '2', got key '%s' and value '%s'", attrs[1].Key, attrs[1].Value) + } + } + switch i { + case 0, 1: + if event.Type != "validate-tx" { + t.Errorf("Expected event type 'validate-tx', got %s", event.Type) + } + if event.MsgIndex != 0 { + t.Errorf("Expected MsgIndex 0, got %d", event.MsgIndex) + } + if attrs[0].Key != senderAddr || attrs[0].Value != senderAddr { + t.Errorf("Expected sender attribute key 'sender' and value 'sender', got key '%s' and value '%s'", attrs[0].Key, attrs[0].Value) + } + case 2, 3: + if event.Type != "handle-msg" { + t.Errorf("Expected event type 'handle-msg', got %s", event.Type) + } + if event.MsgIndex != 1 { + t.Errorf("Expected MsgIndex 1, got %d", event.MsgIndex) + } + if attrs[0].Key != "msg" || attrs[0].Value != "&BoolValue{Value:true,XXX_unrecognized:[],}" { + t.Errorf("Expected msg attribute with value '&BoolValue{Value:true,XXX_unrecognized:[],}', got '%s'", attrs[0].Value) + } + case 4, 5: + if event.Type != "post-tx-exec" { + t.Errorf("Expected event type 'post-tx-exec', got %s", event.Type) + } + if event.MsgIndex != -1 { + t.Errorf("Expected MsgIndex -1, got %d", event.MsgIndex) + } + if attrs[0].Key != senderAddr || attrs[0].Value != senderAddr { + t.Errorf("Expected sender attribute key 'sender' and value 'sender', got key '%s' and value '%s'", attrs[0].Key, attrs[0].Value) + } + } + } }) t.Run("exec tx out of gas", func(t *testing.T) { s := s.clone() mockTx := mock.Tx{ - Sender: []byte("sender"), + Sender: []byte(senderAddr), Msg: &gogotypes.BoolValue{Value: true}, // msg does not matter at all because our handler does nothing. GasLimit: 0, // NO GAS! } diff --git a/server/v2/streaming/plugin.md b/server/v2/streaming/plugin.md index 9eedff9ea2ac..7a1d15bd4307 100644 --- a/server/v2/streaming/plugin.md +++ b/server/v2/streaming/plugin.md @@ -29,7 +29,7 @@ To generate the stubs the local client implementation can call, run the followin make proto-gen ``` -For other languages you'll need to [download](https://github.com/cosmos/cosmos-sdk/blob/main/third_party/proto/README.md) +For other languages you'll need to [download](https://github.com/cosmos/cosmos-sdk/blob/main/proto/README.md#generate) the CosmosSDK protos into your project and compile. For language specific compilation instructions visit [https://github.com/grpc](https://github.com/grpc) and look in the `examples` folder of your language of choice `https://github.com/grpc/grpc-{language}/tree/master/examples` and [https://grpc.io](https://grpc.io) diff --git a/server/v2/types.go b/server/v2/types.go index afa82969131a..7cd15fd10307 100644 --- a/server/v2/types.go +++ b/server/v2/types.go @@ -1,9 +1,9 @@ package serverv2 import ( - gogoproto "github.com/cosmos/gogoproto/proto" "github.com/spf13/viper" + appmodulev2 "cosmossdk.io/core/appmodule/v2" "cosmossdk.io/core/server" "cosmossdk.io/core/transaction" "cosmossdk.io/log" @@ -16,6 +16,6 @@ type AppI[T transaction.Tx] interface { Name() string InterfaceRegistry() server.InterfaceRegistry GetAppManager() *appmanager.AppManager[T] - GetGPRCMethodsToMessageMap() map[string]func() gogoproto.Message + GetQueryHandlers() map[string]appmodulev2.Handler GetStore() any } diff --git a/simapp/go.mod b/simapp/go.mod index 20826a022817..c2eeafc74d92 100644 --- a/simapp/go.mod +++ b/simapp/go.mod @@ -179,7 +179,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.2.0 // indirect @@ -213,7 +213,7 @@ require ( golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/simapp/go.sum b/simapp/go.sum index 68d58cbf59dd..84be5993cd65 100644 --- a/simapp/go.sum +++ b/simapp/go.sum @@ -731,8 +731,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= @@ -983,8 +983,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/simapp/upgrades.go b/simapp/upgrades.go index a4a475490ca2..fc754250b6ce 100644 --- a/simapp/upgrades.go +++ b/simapp/upgrades.go @@ -15,12 +15,12 @@ import ( ) // UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade -// from v0.50.x to v0.51.x +// from v0.52.x to v0.54.x // // NOTE: This upgrade defines a reference implementation of what an upgrade // could look like when an application is migrating from Cosmos SDK version -// v0.50.x to v0.51.x. -const UpgradeName = "v050-to-v051" +// v0.52.x to v0.54.x. +const UpgradeName = "v052-to-v054" func (app SimApp) RegisterUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( diff --git a/simapp/v2/go.mod b/simapp/v2/go.mod index 54ae83f21353..484d0de1e4ee 100644 --- a/simapp/v2/go.mod +++ b/simapp/v2/go.mod @@ -186,7 +186,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rivo/uniseg v0.2.0 // indirect @@ -220,7 +220,7 @@ require ( golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/simapp/v2/go.sum b/simapp/v2/go.sum index 4763f73db611..b0eca7fdef2e 100644 --- a/simapp/v2/go.sum +++ b/simapp/v2/go.sum @@ -735,8 +735,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= @@ -987,8 +987,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/simapp/v2/upgrades.go b/simapp/v2/upgrades.go index 48d557eedb41..2145196fa86d 100644 --- a/simapp/v2/upgrades.go +++ b/simapp/v2/upgrades.go @@ -14,12 +14,12 @@ import ( ) // UpgradeName defines the on-chain upgrade name for the sample SimApp upgrade -// from v0.50.x to v0.51.x +// from v0.52.x to v2 // // NOTE: This upgrade defines a reference implementation of what an upgrade // could look like when an application is migrating from Cosmos SDK version -// v0.50.x to v0.51.x. -const UpgradeName = "v050-to-v051" +// v0.52.x to v2. +const UpgradeName = "v052-to-v2" func (app *SimApp[T]) RegisterUpgradeHandlers() { app.UpgradeKeeper.SetUpgradeHandler( diff --git a/store/go.mod b/store/go.mod index a1d3ad87b431..461c59aa71be 100644 --- a/store/go.mod +++ b/store/go.mod @@ -3,7 +3,7 @@ module cosmossdk.io/store go 1.23 require ( - cosmossdk.io/core v1.0.0-alpha.3 + cosmossdk.io/core v1.0.0-alpha.4 cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 cosmossdk.io/errors v1.0.1 cosmossdk.io/log v1.4.1 diff --git a/store/go.sum b/store/go.sum index f00b75056cd0..ec2fd3014da1 100644 --- a/store/go.sum +++ b/store/go.sum @@ -1,5 +1,5 @@ -cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= -cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= +cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29 h1:NxxUo0GMJUbIuVg0R70e3cbn9eFTEuMr7ev1AFvypdY= cosmossdk.io/core/testing v0.0.0-20240923163230-04da382a9f29/go.mod h1:8s2tPeJtSiQuoyPmr2Ag7meikonISO4Fv4MoO8+ORrs= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= diff --git a/store/streaming/abci/README.md b/store/streaming/abci/README.md index 08aaf12e8a30..1ee13d659766 100644 --- a/store/streaming/abci/README.md +++ b/store/streaming/abci/README.md @@ -27,7 +27,7 @@ To generate the stubs the local client implementation can call, run the followin make proto-gen ``` -For other languages you'll need to [download](https://github.com/cosmos/cosmos-sdk/blob/main/third_party/proto/README.md) +For other languages you'll need to [download](https://github.com/cosmos/cosmos-sdk/blob/main/proto/README.md#generate) the CosmosSDK protos into your project and compile. For language specific compilation instructions visit [https://github.com/grpc](https://github.com/grpc) and look in the `examples` folder of your language of choice `https://github.com/grpc/grpc-{language}/tree/master/examples` and [https://grpc.io](https://grpc.io) diff --git a/store/v2/README.md b/store/v2/README.md index 213f55d05aeb..eb8495c9adc4 100644 --- a/store/v2/README.md +++ b/store/v2/README.md @@ -1,7 +1,7 @@ # Store The `store` package contains the implementation of store/v2, which is the SDK's -abstraction around managing historical and committed state. See [ADR-065](../docs/architecture/adr-065-store-v2.md) +abstraction around managing historical and committed state. See [ADR-065](../../docs/architecture/adr-065-store-v2.md) and [Store v2 Design](https://docs.google.com/document/d/1l6uXIjTPHOOWM5N4sUUmUfCZvePoa5SNfIEtmgvgQSU/edit#heading=h.nz8dqy6wa4g1) for a high-level overview of the design and rationale. ## Usage @@ -42,21 +42,26 @@ sequenceDiagram end ``` -`Prune store keys` does not remove the data from the SC and SS instantly. It only +`PruneStoreKeys` does not remove the data from the SC and SS instantly. It only marks the store keys as pruned. The actual data removal is done by the pruning process of the underlying SS and SC. ## Migration - +The migration from store/v1 to store/v2 is supported by the `MigrationManager` in +the `migration` package. See [Migration Manager](./migration/README.md) for more details. ## Pruning The `root.Store` is NOT responsible for pruning. Rather, pruning is the responsibility of the underlying SS and SC layers. This means pruning can be implementation specific, -such as being synchronous or asynchronous. +such as being synchronous or asynchronous. See [Pruning Manager](./pruning/README.md) for more details. +## State Sync + +The `root.Store` is NOT responsible for state sync. See [Snapshots Manager](./snapshots/README.md) +for more details. ## Test Coverage diff --git a/store/v2/commitment/README.md b/store/v2/commitment/README.md index c9bcf111b4ed..bf730ccb3742 100644 --- a/store/v2/commitment/README.md +++ b/store/v2/commitment/README.md @@ -28,7 +28,11 @@ See this [section](https://docs.google.com/document/d/1l6uXIjTPHOOWM5N4sUUmUfCZv ## Pruning - +Pruning is the process of efficiently managing and removing outdated data from the +State Commitment (SC). To facilitate this, the SC backend must implement the `Pruner` +interface, allowing the `PruningManager` to execute data pruning operations according +to the specified `PruningOption`. Optionally, the SC backend can implement the +`PausablePruner` interface to pause pruning during a commit. ## State Sync diff --git a/store/v2/go.mod b/store/v2/go.mod index 95d69785d137..1a0d84d80a8b 100644 --- a/store/v2/go.mod +++ b/store/v2/go.mod @@ -52,7 +52,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/rs/zerolog v1.33.0 // indirect diff --git a/store/v2/go.sum b/store/v2/go.sum index 18861dba214c..8211266d41a1 100644 --- a/store/v2/go.sum +++ b/store/v2/go.sum @@ -189,8 +189,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= @@ -245,8 +245,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/store/v2/migration/README.md b/store/v2/migration/README.md new file mode 100644 index 000000000000..9db8c9874a8c --- /dev/null +++ b/store/v2/migration/README.md @@ -0,0 +1,111 @@ +# Migration Manager + +The `migration` package contains the `migration.Manager`, which is responsible +for migrating data from `store/v1` to `store/v2`. To ensure a smooth transition, +the process is designed to **lazily** migrate data in the background without blocking +`root.Store` operations. + +## Overview + +The migration process involves several steps: + +1. **Create a snapshot** of the current state while `Commit` operations continue to + function with `store/v1`. +2. **Restore the snapshot** into the new StateStorage (SS) and StateCommitment (SC). +3. **Sync recent state changes** from `store/v1` to the new SS and SC. +4. After syncing, the `Commit` operation will be switched to the new `store/v2`. + +Taking a snapshot is a lightweight operation. The snapshot is not stored on disk but +consumed by the `Restore` process, which replays state changes to the new SS and SC. + +> **Note:** After migration, `store/v2` does **not** support historical queries. +If historical data access is required, a full state migration to `store/v2` is necessary. + +## Usage + +You can create a new `migration.Manager` by calling the following function: + +```go +func NewManager( + db corestore.KVStoreWithBatch, + sm *snapshots.Manager, + ss *storage.StorageStore, + sc *commitment.CommitStore, + logger log.Logger +) *Manager +``` + +* `sc` (Commitment Store) can be `nil`. In that case, the Manager will migrate only + the state storage. +* The migration process is lazy, meaning data is migrated in the background while + `root.Store` remains fully operational. + +To initiate the migration process, call the `Start` method: + +```go +func (m *Manager) Start(ctx context.Context) error +``` + +> **Note:** It should be called by the RootStore, running in the background. + +## Migration Flow + +```mermaid +sequenceDiagram + autonumber + + participant A as RootStore + participant B as MigrationManager + participant C as SnapshotsManager + participant D as StateCommitment + participant E as StateStorage + + A->>B: Start + loop Old Data Migration + B->>C: Create Snapshot + C->>B: Stream Snapshot + B->>D: State Sync (Restore) + B->>E: Write Changeset (Restore) + end + + loop New Commit Data Sync + A->>B: Commit(Changeset) + B->>B: Store Changeset + B->>D: Commit Changeset + B->>E: Write Changeset + end + + B->>A: Switch to new store/v2 +``` + +## Key Considerations + +### Laziness and Background Operation + +The migration is performed lazily, meaning it occurs in the background without +interrupting the current operations on root.Store. This allows the chain to continue +running while data is gradually migrated to `store/v2`. State synchronization ensures +that any new state changes during the migration are also applied to `store/v2`. + +However, note that there may be a performance impact depending on the size of the data +being migrated, and it’s essential to monitor the migration process in production +environments. + +### Handling Failures and Rollbacks + +It is important to consider how the migration manager handles errors or system failures +during the migration process: + +* If the migration fails, there is no impact on the existing `store/v1` operations, + but need to restart the migration process from the scratch. +* In the event of a critical failure after migration, a rollback may not be possible, + and it is needed to keep the `store/v1` backup for a certain period. + +### Impact on Historical Queries + +After the migration, the new `store/v2` does not support historical queries. +This limitation should be clearly understood before starting the migration process, +especially if the node relies on historical data for any operations. + +If historical queries are required, users must fully migrate all historical data to `store/v2`. +Alternatively, keeping store/v1 accessible for historical queries could be an option. \ No newline at end of file diff --git a/store/v2/storage/README.md b/store/v2/storage/README.md index 48606d6c19c1..5467bff24a05 100644 --- a/store/v2/storage/README.md +++ b/store/v2/storage/README.md @@ -70,13 +70,10 @@ Iterate/backend_rocksdb_versiondb_opts-10 778ms ± 0% ## Pruning -Pruning is an implementation and responsibility of the underlying SS backend. -Specifically, the `StorageStore` accepts `store.PruningOption` which defines the -pruning configuration. During `ApplyChangeset`, the `StorageStore` will check if -pruning should occur based on the current height being committed. If so, it will -delegate a `Prune` call on the underlying SS backend, which can be defined specific -to the implementation, e.g. asynchronous or synchronous. - +Pruning is the process of efficiently managing and removing outdated or redundant +data from the State Storage (SS). To facilitate this, the SS backend must implement +the `Pruner` interface, allowing the `PruningManager` to execute data pruning operations +according to the specified `PruningOption`. ## State Sync diff --git a/tests/go.mod b/tests/go.mod index e729a6f42d44..bbc2a3c3e485 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -176,7 +176,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect @@ -210,7 +210,7 @@ require ( golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/tests/go.sum b/tests/go.sum index 5463df512657..b2cfe1aa475e 100644 --- a/tests/go.sum +++ b/tests/go.sum @@ -722,8 +722,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= @@ -972,8 +972,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/tests/integration/rapidgen/rapidgen.go b/tests/integration/rapidgen/rapidgen.go index e33e794b00f2..0060ca1976ce 100644 --- a/tests/integration/rapidgen/rapidgen.go +++ b/tests/integration/rapidgen/rapidgen.go @@ -222,7 +222,6 @@ var ( NonsignableTypes = []GeneratedType{ GenType(&authtypes.Params{}, &authapi.Params{}, GenOpts), GenType(&authtypes.BaseAccount{}, &authapi.BaseAccount{}, GenOpts.WithAnyTypes(&ed25519.PubKey{})), - GenType(&authtypes.ModuleAccount{}, &authapi.ModuleAccount{}, GenOpts.WithAnyTypes(&ed25519.PubKey{})), GenType(&authtypes.ModuleCredential{}, &authapi.ModuleCredential{}, GenOpts), GenType(&authztypes.GenericAuthorization{}, &authzapi.GenericAuthorization{}, GenOpts), @@ -260,7 +259,9 @@ var ( GenType(&slashingtypes.Params{}, &slashingapi.Params{}, GenOpts.WithDisallowNil()), - GenType(&stakingtypes.StakeAuthorization{}, &stakingapi.StakeAuthorization{}, GenOpts), + // JSON ordering of one of fields to be fixed in https://github.com/cosmos/cosmos-sdk/pull/21782 + // TODO uncomment once merged + // GenType(&stakingtypes.StakeAuthorization{}, &stakingapi.StakeAuthorization{}, GenOpts), GenType(&upgradetypes.CancelSoftwareUpgradeProposal{}, &upgradeapi.CancelSoftwareUpgradeProposal{}, GenOpts), //nolint:staticcheck // testing legacy code path GenType(&upgradetypes.SoftwareUpgradeProposal{}, &upgradeapi.SoftwareUpgradeProposal{}, GenOpts.WithDisallowNil()), //nolint:staticcheck // testing legacy code path diff --git a/tests/integration/tx/aminojson/aminojson_test.go b/tests/integration/tx/aminojson/aminojson_test.go index c17e845fe596..cf9695b4b451 100644 --- a/tests/integration/tx/aminojson/aminojson_test.go +++ b/tests/integration/tx/aminojson/aminojson_test.go @@ -1,10 +1,9 @@ package aminojson import ( - "context" + "bytes" "fmt" - "reflect" - "strings" + stdmath "math" "testing" "time" @@ -12,26 +11,12 @@ import ( gogoproto "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/require" "google.golang.org/protobuf/proto" - "google.golang.org/protobuf/types/known/anypb" - "google.golang.org/protobuf/types/known/durationpb" - "google.golang.org/protobuf/types/known/timestamppb" "pgregory.net/rapid" authapi "cosmossdk.io/api/cosmos/auth/v1beta1" - authzapi "cosmossdk.io/api/cosmos/authz/v1beta1" bankapi "cosmossdk.io/api/cosmos/bank/v1beta1" v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1" - "cosmossdk.io/api/cosmos/crypto/ed25519" - multisigapi "cosmossdk.io/api/cosmos/crypto/multisig" - "cosmossdk.io/api/cosmos/crypto/secp256k1" - distapi "cosmossdk.io/api/cosmos/distribution/v1beta1" - gov_v1_api "cosmossdk.io/api/cosmos/gov/v1" - gov_v1beta1_api "cosmossdk.io/api/cosmos/gov/v1beta1" msgv1 "cosmossdk.io/api/cosmos/msg/v1" - slashingapi "cosmossdk.io/api/cosmos/slashing/v1beta1" - stakingapi "cosmossdk.io/api/cosmos/staking/v1beta1" - txv1beta1 "cosmossdk.io/api/cosmos/tx/v1beta1" - vestingapi "cosmossdk.io/api/cosmos/vesting/v1beta1" "cosmossdk.io/math" authztypes "cosmossdk.io/x/authz" authzmodule "cosmossdk.io/x/authz/module" @@ -52,7 +37,6 @@ import ( "cosmossdk.io/x/staking" stakingtypes "cosmossdk.io/x/staking/types" "cosmossdk.io/x/tx/signing/aminojson" - signing_testutil "cosmossdk.io/x/tx/signing/testutil" "cosmossdk.io/x/upgrade" codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil" @@ -61,17 +45,13 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keys/multisig" secp256k1types "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" "github.com/cosmos/cosmos-sdk/tests/integration/rapidgen" + "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal" gogo_testpb "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal/gogo/testpb" - pulsar_testpb "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal/pulsar/testpb" "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/bech32" "github.com/cosmos/cosmos-sdk/types/module/testutil" - signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" - "github.com/cosmos/cosmos-sdk/x/auth/signing" - "github.com/cosmos/cosmos-sdk/x/auth/tx" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" "github.com/cosmos/cosmos-sdk/x/auth/vesting" vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" @@ -92,13 +72,23 @@ import ( // In order for step 3 to work certain restrictions on the data generated in step 1 must be enforced and are described // by the mutation of genOpts passed to the generator. func TestAminoJSON_Equivalence(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig( - codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, - consensus.AppModule{}, distribution.AppModule{}, evidence.AppModule{}, feegrantmodule.AppModule{}, - gov.AppModule{}, groupmodule.AppModule{}, mint.AppModule{}, - slashing.AppModule{}, staking.AppModule{}, upgrade.AppModule{}, vesting.AppModule{}) - legacytx.RegressionTestingAminoCodec = encCfg.Amino - aj := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: true}) + fixture := internal.NewSigningFixture(t, internal.SigningFixtureOptions{}, + auth.AppModule{}, + authzmodule.AppModule{}, + bank.AppModule{}, + consensus.AppModule{}, + distribution.AppModule{}, + evidence.AppModule{}, + feegrantmodule.AppModule{}, + gov.AppModule{}, + groupmodule.AppModule{}, + mint.AppModule{}, + slashing.AppModule{}, + staking.AppModule{}, + upgrade.AppModule{}, + vesting.AppModule{}, + ) + aj := aminojson.NewEncoder(aminojson.EncoderOptions{}) for _, tt := range rapidgen.DefaultGeneratedTypes { desc := tt.Pulsar.ProtoReflect().Descriptor() @@ -106,7 +96,7 @@ func TestAminoJSON_Equivalence(t *testing.T) { t.Run(name, func(t *testing.T) { gen := rapidproto.MessageGenerator(tt.Pulsar, tt.Opts) fmt.Printf("testing %s\n", tt.Pulsar.ProtoReflect().Descriptor().FullName()) - rapid.Check(t, func(t *rapid.T) { + rapid.Check(t, func(r *rapid.T) { // uncomment to debug; catch a panic and inspect application state // defer func() { // if r := recover(); r != nil { @@ -115,39 +105,28 @@ func TestAminoJSON_Equivalence(t *testing.T) { // } // }() - msg := gen.Draw(t, "msg") + msg := gen.Draw(r, "msg") postFixPulsarMessage(msg) - // txBuilder.GetTx will fail if the msg has no signers - // so it does not make sense to run these cases, apparently. - signers, err := encCfg.TxConfig.SigningContext().GetSigners(msg) - if len(signers) == 0 { - // skip - return - } - if err != nil { - if strings.Contains(err.Error(), "empty address string is not allowed") { - return - } - require.NoError(t, err) - } gogo := tt.Gogo sanity := tt.Pulsar protoBz, err := proto.Marshal(msg) - require.NoError(t, err) + require.NoError(r, err) err = proto.Unmarshal(protoBz, sanity) - require.NoError(t, err) + require.NoError(r, err) - err = encCfg.Codec.Unmarshal(protoBz, gogo) - require.NoError(t, err) + err = fixture.UnmarshalGogoProto(protoBz, gogo) + require.NoError(r, err) - legacyAminoJSON, err := encCfg.Amino.MarshalJSON(gogo) - require.NoError(t, err) + legacyAminoJSON := fixture.MarshalLegacyAminoJSON(t, gogo) aminoJSON, err := aj.Marshal(msg) - require.NoError(t, err) - require.Equal(t, string(legacyAminoJSON), string(aminoJSON)) + require.NoError(r, err) + if !bytes.Equal(legacyAminoJSON, aminoJSON) { + require.Failf(r, "JSON mismatch", "legacy: %s\n x/tx: %s\n", + string(legacyAminoJSON), string(aminoJSON)) + } // test amino json signer handler equivalence if !proto.HasExtension(desc.Options(), msgv1.E_Signer) { @@ -155,368 +134,240 @@ func TestAminoJSON_Equivalence(t *testing.T) { return } - handlerOptions := signing_testutil.HandlerArgumentOptions{ - ChainID: "test-chain", - Memo: "sometestmemo", - Msg: tt.Pulsar, - AccNum: 1, - AccSeq: 2, - SignerAddress: "signerAddress", - Fee: &txv1beta1.Fee{ - Amount: []*v1beta1.Coin{{Denom: "uatom", Amount: "1000"}}, - }, - } - - signerData, txData, err := signing_testutil.MakeHandlerArguments(handlerOptions) - require.NoError(t, err) - - handler := aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{}) - signBz, err := handler.GetSignBytes(context.Background(), signerData, txData) - require.NoError(t, err) - - legacyHandler := tx.NewSignModeLegacyAminoJSONHandler() - txBuilder := encCfg.TxConfig.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs([]types.Msg{tt.Gogo}...)) - txBuilder.SetMemo(handlerOptions.Memo) - txBuilder.SetFeeAmount(types.Coins{types.NewInt64Coin("uatom", 1000)}) - theTx := txBuilder.GetTx() - - legacySigningData := signing.SignerData{ - ChainID: handlerOptions.ChainID, - Address: handlerOptions.SignerAddress, - AccountNumber: handlerOptions.AccNum, - Sequence: handlerOptions.AccSeq, - } - legacySignBz, err := legacyHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - legacySigningData, theTx) - require.NoError(t, err) - require.Equal(t, string(legacySignBz), string(signBz)) + fixture.RequireLegacyAminoEquivalent(t, gogo) }) }) } } -func newAny(t *testing.T, msg proto.Message) *anypb.Any { - t.Helper() - bz, err := proto.Marshal(msg) - require.NoError(t, err) - typeName := fmt.Sprintf("/%s", msg.ProtoReflect().Descriptor().FullName()) - return &anypb.Any{ - TypeUrl: typeName, - Value: bz, - } -} - // TestAminoJSON_LegacyParity tests that the Encoder encoder produces the same output as the Encoder encoder. func TestAminoJSON_LegacyParity(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, + fixture := internal.NewSigningFixture(t, internal.SigningFixtureOptions{}, + auth.AppModule{}, authzmodule.AppModule{}, bank.AppModule{}, distribution.AppModule{}, slashing.AppModule{}, staking.AppModule{}, vesting.AppModule{}, gov.AppModule{}) - legacytx.RegressionTestingAminoCodec = encCfg.Amino + aj := aminojson.NewEncoder(aminojson.EncoderOptions{}) - aj := aminojson.NewEncoder(aminojson.EncoderOptions{DoNotSortFields: true}) addr1 := types.AccAddress("addr1") now := time.Now() - genericAuth, _ := codectypes.NewAnyWithValue(&authztypes.GenericAuthorization{Msg: "foo"}) - genericAuthPulsar := newAny(t, &authzapi.GenericAuthorization{Msg: "foo"}) pubkeyAny, _ := codectypes.NewAnyWithValue(&secp256k1types.PubKey{Key: []byte("foo")}) - pubkeyAnyPulsar := newAny(t, &secp256k1.PubKey{Key: []byte("foo")}) - dec10bz, _ := math.LegacyNewDec(10).Marshal() - int123bz, _ := math.NewInt(123).Marshal() + dec5point4 := math.LegacyMustNewDecFromStr("5.4") + failingBaseAccount := authtypes.NewBaseAccountWithAddress(addr1) + failingBaseAccount.AccountNumber = stdmath.MaxUint64 cases := map[string]struct { - gogo gogoproto.Message - pulsar proto.Message - pulsarMarshalFails bool - - // this will fail in cases where a lossy encoding of an empty array to protobuf occurs. the unmarshalled bytes - // represent the array as nil, and a subsequent marshal to JSON represent the array as null instead of empty. - roundTripUnequal bool - - // pulsar does not support marshaling a math.Dec as anything except a string. Therefore, we cannot unmarshal - // a pulsar encoded Math.dec (the string representation of a Decimal) into a gogo Math.dec (expecting an int64). - protoUnmarshalFails bool + gogo gogoproto.Message + fails bool }{ - "auth/params": {gogo: &authtypes.Params{TxSigLimit: 10}, pulsar: &authapi.Params{TxSigLimit: 10}}, - "auth/module_account": { + "auth/params": { + gogo: &authtypes.Params{TxSigLimit: 10}, + }, + "auth/module_account_nil_permissions": { gogo: &authtypes.ModuleAccount{ - BaseAccount: authtypes.NewBaseAccountWithAddress(addr1), Permissions: []string{}, + BaseAccount: authtypes.NewBaseAccountWithAddress( + addr1, + ), }, - pulsar: &authapi.ModuleAccount{ - BaseAccount: &authapi.BaseAccount{Address: addr1.String()}, Permissions: []string{}, + }, + "auth/module_account/max_uint64": { + gogo: &authtypes.ModuleAccount{ + BaseAccount: failingBaseAccount, }, - roundTripUnequal: true, + fails: true, + }, + "auth/module_account_empty_permissions": { + gogo: &authtypes.ModuleAccount{ + BaseAccount: authtypes.NewBaseAccountWithAddress( + addr1, + ), + // empty set and nil are indistinguishable from the protoreflect API since they both + // marshal to zero proto bytes, there empty set is not supported. + Permissions: []string{}, + }, + fails: true, }, "auth/base_account": { - gogo: &authtypes.BaseAccount{Address: addr1.String(), PubKey: pubkeyAny}, - pulsar: &authapi.BaseAccount{Address: addr1.String(), PubKey: pubkeyAnyPulsar}, + gogo: &authtypes.BaseAccount{Address: addr1.String(), PubKey: pubkeyAny, AccountNumber: 1, Sequence: 2}, }, "authz/msg_grant": { gogo: &authztypes.MsgGrant{ + Granter: addr1.String(), Grantee: addr1.String(), Grant: authztypes.Grant{Expiration: &now, Authorization: genericAuth}, }, - pulsar: &authzapi.MsgGrant{ - Grant: &authzapi.Grant{Expiration: timestamppb.New(now), Authorization: genericAuthPulsar}, - }, }, "authz/msg_update_params": { - gogo: &authtypes.MsgUpdateParams{Params: authtypes.Params{TxSigLimit: 10}}, - pulsar: &authapi.MsgUpdateParams{Params: &authapi.Params{TxSigLimit: 10}}, + gogo: &authtypes.MsgUpdateParams{Params: authtypes.Params{TxSigLimit: 10}}, }, "authz/msg_exec/empty_msgs": { - gogo: &authztypes.MsgExec{Msgs: []*codectypes.Any{}}, - pulsar: &authzapi.MsgExec{Msgs: []*anypb.Any{}}, + gogo: &authztypes.MsgExec{Msgs: []*codectypes.Any{}}, }, "distribution/delegator_starting_info": { - gogo: &disttypes.DelegatorStartingInfo{}, - pulsar: &distapi.DelegatorStartingInfo{}, + gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)}, }, "distribution/delegator_starting_info/non_zero_dec": { - gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)}, - pulsar: &distapi.DelegatorStartingInfo{Stake: "10.000000000000000000"}, - protoUnmarshalFails: true, + gogo: &disttypes.DelegatorStartingInfo{Stake: math.LegacyNewDec(10)}, }, "distribution/delegation_delegator_reward": { - gogo: &disttypes.DelegationDelegatorReward{}, - pulsar: &distapi.DelegationDelegatorReward{}, + gogo: &disttypes.DelegationDelegatorReward{}, }, "distribution/msg_withdraw_delegator_reward": { - gogo: &disttypes.MsgWithdrawDelegatorReward{DelegatorAddress: "foo"}, - pulsar: &distapi.MsgWithdrawDelegatorReward{DelegatorAddress: "foo"}, + gogo: &disttypes.MsgWithdrawDelegatorReward{DelegatorAddress: "foo"}, }, "crypto/ed25519": { - gogo: &ed25519types.PubKey{Key: []byte("key")}, - pulsar: &ed25519.PubKey{Key: []byte("key")}, + gogo: &ed25519types.PubKey{Key: []byte("key")}, }, "crypto/secp256k1": { - gogo: &secp256k1types.PubKey{Key: []byte("key")}, - pulsar: &secp256k1.PubKey{Key: []byte("key")}, + gogo: &secp256k1types.PubKey{Key: []byte("key")}, }, "crypto/legacy_amino_pubkey": { - gogo: &multisig.LegacyAminoPubKey{PubKeys: []*codectypes.Any{pubkeyAny}}, - pulsar: &multisigapi.LegacyAminoPubKey{PublicKeys: []*anypb.Any{pubkeyAnyPulsar}}, + gogo: &multisig.LegacyAminoPubKey{PubKeys: []*codectypes.Any{pubkeyAny}}, }, - "crypto/legacy_amino_pubkey/empty": { - gogo: &multisig.LegacyAminoPubKey{}, - pulsar: &multisigapi.LegacyAminoPubKey{}, + "crypto/legacy_amino_pubkey_empty": { + gogo: &multisig.LegacyAminoPubKey{}, }, "consensus/evidence_params/duration": { - gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: 1e9 + 7}, - pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{Seconds: 1, Nanos: 7}}, + gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: 1e9 + 7}, }, "consensus/evidence_params/big_duration": { - gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999}, - pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{ - Seconds: rapidproto.MaxDurationSeconds, Nanos: 999999999, - }}, + gogo: &gov_v1beta1_types.VotingParams{ + VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999, + }, }, "consensus/evidence_params/too_big_duration": { - gogo: &gov_v1beta1_types.VotingParams{VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999}, - pulsar: &gov_v1beta1_api.VotingParams{VotingPeriod: &durationpb.Duration{ - Seconds: rapidproto.MaxDurationSeconds + 1, Nanos: 999999999, - }}, - pulsarMarshalFails: true, + gogo: &gov_v1beta1_types.VotingParams{ + VotingPeriod: time.Duration(rapidproto.MaxDurationSeconds*1e9) + 999999999, + }, }, // amino.dont_omitempty + empty/nil lists produce some surprising results "bank/send_authorization/empty_coins": { - gogo: &banktypes.SendAuthorization{SpendLimit: []types.Coin{}}, - pulsar: &bankapi.SendAuthorization{SpendLimit: []*v1beta1.Coin{}}, + gogo: &banktypes.SendAuthorization{SpendLimit: []types.Coin{}}, }, "bank/send_authorization/nil_coins": { - gogo: &banktypes.SendAuthorization{SpendLimit: nil}, - pulsar: &bankapi.SendAuthorization{SpendLimit: nil}, + gogo: &banktypes.SendAuthorization{SpendLimit: nil}, }, "bank/send_authorization/empty_list": { - gogo: &banktypes.SendAuthorization{AllowList: []string{}}, - pulsar: &bankapi.SendAuthorization{AllowList: []string{}}, + gogo: &banktypes.SendAuthorization{AllowList: []string{}}, }, "bank/send_authorization/nil_list": { - gogo: &banktypes.SendAuthorization{AllowList: nil}, - pulsar: &bankapi.SendAuthorization{AllowList: nil}, + gogo: &banktypes.SendAuthorization{AllowList: nil}, }, "bank/msg_multi_send/nil_everything": { - gogo: &banktypes.MsgMultiSend{}, - pulsar: &bankapi.MsgMultiSend{}, + gogo: &banktypes.MsgMultiSend{}, }, "gov/v1_msg_submit_proposal": { - gogo: &gov_v1_types.MsgSubmitProposal{}, - pulsar: &gov_v1_api.MsgSubmitProposal{}, + gogo: &gov_v1_types.MsgSubmitProposal{}, }, - "slashing/params/empty_dec": { - gogo: &slashingtypes.Params{DowntimeJailDuration: 1e9 + 7}, - pulsar: &slashingapi.Params{DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7}}, - }, - // This test cases demonstrates the expected contract and proper way to set a cosmos.Dec field represented - // as bytes in protobuf message, namely: - // dec10bz, _ := types.NewDec(10).Marshal() "slashing/params/dec": { gogo: &slashingtypes.Params{ - DowntimeJailDuration: 1e9 + 7, - MinSignedPerWindow: math.LegacyNewDec(10), - }, - pulsar: &slashingapi.Params{ - DowntimeJailDuration: &durationpb.Duration{Seconds: 1, Nanos: 7}, - MinSignedPerWindow: dec10bz, + DowntimeJailDuration: 1e9 + 7, + MinSignedPerWindow: math.LegacyNewDec(10), + SlashFractionDoubleSign: math.LegacyZeroDec(), + SlashFractionDowntime: math.LegacyZeroDec(), }, }, "staking/msg_update_params": { gogo: &stakingtypes.MsgUpdateParams{ Params: stakingtypes.Params{ - UnbondingTime: 0, - KeyRotationFee: types.Coin{}, - }, - }, - pulsar: &stakingapi.MsgUpdateParams{ - Params: &stakingapi.Params{ - UnbondingTime: &durationpb.Duration{Seconds: 0}, - KeyRotationFee: &v1beta1.Coin{}, + UnbondingTime: 0, + KeyRotationFee: types.Coin{}, + MinCommissionRate: math.LegacyZeroDec(), }, }, }, "staking/create_validator": { - gogo: &stakingtypes.MsgCreateValidator{Pubkey: pubkeyAny}, - pulsar: &stakingapi.MsgCreateValidator{ - Pubkey: pubkeyAnyPulsar, - Description: &stakingapi.Description{ - Metadata: &stakingapi.Metadata{}, + gogo: &stakingtypes.MsgCreateValidator{ + Pubkey: pubkeyAny, + Commission: stakingtypes.CommissionRates{ + Rate: dec5point4, + MaxRate: math.LegacyZeroDec(), + MaxChangeRate: math.LegacyZeroDec(), }, - Commission: &stakingapi.CommissionRates{}, - Value: &v1beta1.Coin{}, + MinSelfDelegation: math.NewIntFromUint64(10), }, }, "staking/msg_cancel_unbonding_delegation_response": { - gogo: &stakingtypes.MsgCancelUnbondingDelegationResponse{}, - pulsar: &stakingapi.MsgCancelUnbondingDelegationResponse{}, + gogo: &stakingtypes.MsgCancelUnbondingDelegationResponse{}, }, "staking/stake_authorization_empty": { - gogo: &stakingtypes.StakeAuthorization{}, - pulsar: &stakingapi.StakeAuthorization{}, + gogo: &stakingtypes.StakeAuthorization{}, }, "staking/stake_authorization_allow": { gogo: &stakingtypes.StakeAuthorization{ + MaxTokens: &types.Coin{Denom: "foo", Amount: math.NewInt(123)}, Validators: &stakingtypes.StakeAuthorization_AllowList{ - AllowList: &stakingtypes.StakeAuthorization_Validators{Address: []string{"foo"}}, + AllowList: &stakingtypes.StakeAuthorization_Validators{ + Address: []string{"foo"}, + }, }, + AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, }, - pulsar: &stakingapi.StakeAuthorization{ - Validators: &stakingapi.StakeAuthorization_AllowList{ - AllowList: &stakingapi.StakeAuthorization_Validators{Address: []string{"foo"}}, + }, + "staking/stake_authorization_deny": { + gogo: &stakingtypes.StakeAuthorization{ + MaxTokens: &types.Coin{Denom: "foo", Amount: math.NewInt(123)}, + Validators: &stakingtypes.StakeAuthorization_DenyList{ + DenyList: &stakingtypes.StakeAuthorization_Validators{}, }, + AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE, }, + // to be fixed in https://github.com/cosmos/cosmos-sdk/pull/21782 + // TODO remove once merged + fails: true, }, "vesting/base_account_empty": { - gogo: &vestingtypes.BaseVestingAccount{BaseAccount: &authtypes.BaseAccount{}}, - pulsar: &vestingapi.BaseVestingAccount{BaseAccount: &authapi.BaseAccount{}}, + gogo: &vestingtypes.BaseVestingAccount{BaseAccount: &authtypes.BaseAccount{}}, }, "vesting/base_account_pubkey": { - gogo: &vestingtypes.BaseVestingAccount{BaseAccount: &authtypes.BaseAccount{PubKey: pubkeyAny}}, - pulsar: &vestingapi.BaseVestingAccount{BaseAccount: &authapi.BaseAccount{PubKey: pubkeyAnyPulsar}}, + gogo: &vestingtypes.BaseVestingAccount{ + BaseAccount: &authtypes.BaseAccount{PubKey: pubkeyAny}, + }, }, "math/int_as_string": { - gogo: &gogo_testpb.IntAsString{IntAsString: math.NewInt(123)}, - pulsar: &pulsar_testpb.IntAsString{IntAsString: "123"}, + gogo: &gogo_testpb.IntAsString{IntAsString: math.NewInt(123)}, }, "math/int_as_string/empty": { - gogo: &gogo_testpb.IntAsString{}, - pulsar: &pulsar_testpb.IntAsString{}, + gogo: &gogo_testpb.IntAsString{}, }, "math/int_as_bytes": { - gogo: &gogo_testpb.IntAsBytes{IntAsBytes: math.NewInt(123)}, - pulsar: &pulsar_testpb.IntAsBytes{IntAsBytes: int123bz}, + gogo: &gogo_testpb.IntAsBytes{IntAsBytes: math.NewInt(123)}, }, "math/int_as_bytes/empty": { - gogo: &gogo_testpb.IntAsBytes{}, - pulsar: &pulsar_testpb.IntAsBytes{}, + gogo: &gogo_testpb.IntAsBytes{}, }, } for name, tc := range cases { t.Run(name, func(t *testing.T) { - gogoBytes, err := encCfg.Amino.MarshalJSON(tc.gogo) + legacyBytes := fixture.MarshalLegacyAminoJSON(t, tc.gogo) + dynamicBytes, err := aj.Marshal(fixture.DynamicMessage(t, tc.gogo)) require.NoError(t, err) - pulsarBytes, err := aj.Marshal(tc.pulsar) - if tc.pulsarMarshalFails { - require.Error(t, err) + t.Logf("legacy: %s\n", string(legacyBytes)) + t.Logf(" sut: %s\n", string(dynamicBytes)) + if tc.fails { + require.NotEqual(t, string(legacyBytes), string(dynamicBytes)) return } - require.NoError(t, err) - - fmt.Printf("pulsar: %s\n", string(pulsarBytes)) - fmt.Printf(" gogo: %s\n", string(gogoBytes)) - require.Equal(t, string(gogoBytes), string(pulsarBytes)) - - pulsarProtoBytes, err := proto.Marshal(tc.pulsar) - require.NoError(t, err) - - gogoType := reflect.TypeOf(tc.gogo).Elem() - newGogo := reflect.New(gogoType).Interface().(gogoproto.Message) - - err = encCfg.Codec.Unmarshal(pulsarProtoBytes, newGogo) - if tc.protoUnmarshalFails { - require.Error(t, err) - return - } - require.NoError(t, err) - - newGogoBytes, err := encCfg.Amino.MarshalJSON(newGogo) - require.NoError(t, err) - if tc.roundTripUnequal { - require.NotEqual(t, string(gogoBytes), string(newGogoBytes)) - return - } - require.Equal(t, string(gogoBytes), string(newGogoBytes)) + require.Equal(t, string(legacyBytes), string(dynamicBytes)) // test amino json signer handler equivalence - msg, ok := tc.gogo.(legacytx.LegacyMsg) - if !ok { + if !proto.HasExtension(fixture.MessageDescriptor(t, tc.gogo).Options(), msgv1.E_Signer) { // not signable return } - - handlerOptions := signing_testutil.HandlerArgumentOptions{ - ChainID: "test-chain", - Memo: "sometestmemo", - Msg: tc.pulsar, - AccNum: 1, - AccSeq: 2, - SignerAddress: "signerAddress", - Fee: &txv1beta1.Fee{ - Amount: []*v1beta1.Coin{{Denom: "uatom", Amount: "1000"}}, - }, - } - - signerData, txData, err := signing_testutil.MakeHandlerArguments(handlerOptions) - require.NoError(t, err) - - handler := aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{}) - signBz, err := handler.GetSignBytes(context.Background(), signerData, txData) - require.NoError(t, err) - - legacyHandler := tx.NewSignModeLegacyAminoJSONHandler() - txBuilder := encCfg.TxConfig.NewTxBuilder() - require.NoError(t, txBuilder.SetMsgs([]types.Msg{msg}...)) - txBuilder.SetMemo(handlerOptions.Memo) - txBuilder.SetFeeAmount(types.Coins{types.NewInt64Coin("uatom", 1000)}) - theTx := txBuilder.GetTx() - - legacySigningData := signing.SignerData{ - ChainID: handlerOptions.ChainID, - Address: handlerOptions.SignerAddress, - AccountNumber: handlerOptions.AccNum, - Sequence: handlerOptions.AccSeq, - } - legacySignBz, err := legacyHandler.GetSignBytes(signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, - legacySigningData, theTx) - require.NoError(t, err) - require.Equal(t, string(legacySignBz), string(signBz)) + fixture.RequireLegacyAminoEquivalent(t, tc.gogo) }) } } func TestSendAuthorization(t *testing.T) { - encCfg := testutil.MakeTestEncodingConfig(codectestutil.CodecOptions{}, auth.AppModule{}, authzmodule.AppModule{}, - distribution.AppModule{}, bank.AppModule{}) + encCfg := testutil.MakeTestEncodingConfig( + codectestutil.CodecOptions{}, + auth.AppModule{}, + authzmodule.AppModule{}, + distribution.AppModule{}, + bank.AppModule{}, + ) aj := aminojson.NewEncoder(aminojson.EncoderOptions{}) diff --git a/tests/integration/tx/context_test.go b/tests/integration/tx/context_test.go index ffe21c2053cb..eb6ce3250160 100644 --- a/tests/integration/tx/context_test.go +++ b/tests/integration/tx/context_test.go @@ -4,7 +4,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/proto" "cosmossdk.io/depinject" "cosmossdk.io/log" @@ -12,21 +11,14 @@ import ( "cosmossdk.io/x/tx/signing" codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal" "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal/pulsar/testpb" "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" ) -func ProvideCustomGetSigners() signing.CustomGetSigner { - return signing.CustomGetSigner{ - MsgType: proto.MessageName(&testpb.TestRepeatedFields{}), - Fn: func(msg proto.Message) ([][]byte, error) { - testMsg := msg.(*testpb.TestRepeatedFields) - // arbitrary logic - signer := testMsg.NullableDontOmitempty[1].Value - return [][]byte{[]byte(signer)}, nil - }, - } +func ProvideCustomGetSigner() signing.CustomGetSigner { + return internal.TestRepeatedFieldsSigner } func TestDefineCustomGetSigners(t *testing.T) { @@ -41,7 +33,7 @@ func TestDefineCustomGetSigners(t *testing.T) { configurator.ConsensusModule(), ), depinject.Supply(log.NewNopLogger()), - depinject.Provide(ProvideCustomGetSigners), + depinject.Provide(ProvideCustomGetSigner), ), &interfaceRegistry, ) diff --git a/tests/integration/tx/internal/util.go b/tests/integration/tx/internal/util.go new file mode 100644 index 000000000000..d2e654a58816 --- /dev/null +++ b/tests/integration/tx/internal/util.go @@ -0,0 +1,221 @@ +package internal + +import ( + "bytes" + "context" + "encoding/json" + "testing" + + gogoproto "github.com/cosmos/gogoproto/proto" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" + "google.golang.org/protobuf/types/dynamicpb" + + "cosmossdk.io/core/transaction" + "cosmossdk.io/x/tx/signing" + "cosmossdk.io/x/tx/signing/aminojson" + + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + codectypes "github.com/cosmos/cosmos-sdk/codec/types" + "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/tests/integration/tx/internal/pulsar/testpb" + "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/module" + signingtypes "github.com/cosmos/cosmos-sdk/types/tx/signing" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" + authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" + "github.com/cosmos/cosmos-sdk/x/auth/tx" +) + +var TestRepeatedFieldsSigner = signing.CustomGetSigner{ + MsgType: proto.MessageName(&testpb.TestRepeatedFields{}), + Fn: func(msg proto.Message) ([][]byte, error) { + testMsg := msg.(*testpb.TestRepeatedFields) + // arbitrary logic + signer := testMsg.NullableDontOmitempty[1].Value + return [][]byte{[]byte(signer)}, nil + }, +} + +type noOpAddressCodec struct{} + +func (a noOpAddressCodec) StringToBytes(text string) ([]byte, error) { + return []byte(text), nil +} + +func (a noOpAddressCodec) BytesToString(bz []byte) (string, error) { + return string(bz), nil +} + +type SigningFixture struct { + txConfig client.TxConfig + legacy *codec.LegacyAmino + protoCodec *codec.ProtoCodec + options SigningFixtureOptions + registry codectypes.InterfaceRegistry +} + +type SigningFixtureOptions struct { + DoNotSortFields bool +} + +func NewSigningFixture( + t *testing.T, + options SigningFixtureOptions, + modules ...module.AppModule, +) *SigningFixture { + t.Helper() + // set up transaction and signing infra + addressCodec, valAddressCodec := noOpAddressCodec{}, noOpAddressCodec{} + customGetSigners := []signing.CustomGetSigner{TestRepeatedFieldsSigner} + interfaceRegistry, _, err := codec.ProvideInterfaceRegistry( + addressCodec, + valAddressCodec, + customGetSigners, + ) + require.NoError(t, err) + protoCodec := codec.ProvideProtoCodec(interfaceRegistry) + signingOptions := &signing.Options{ + FileResolver: interfaceRegistry, + AddressCodec: addressCodec, + ValidatorAddressCodec: valAddressCodec, + } + for _, customGetSigner := range customGetSigners { + signingOptions.DefineCustomGetSigners(customGetSigner.MsgType, customGetSigner.Fn) + } + txConfig, err := tx.NewTxConfigWithOptions( + protoCodec, + tx.ConfigOptions{ + EnabledSignModes: []signingtypes.SignMode{ + signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + }, + SigningOptions: signingOptions, + }) + require.NoError(t, err) + + legacyAminoCodec := codec.NewLegacyAmino() + mb := module.NewManager(modules...) + std.RegisterLegacyAminoCodec(legacyAminoCodec) + std.RegisterInterfaces(interfaceRegistry) + mb.RegisterLegacyAminoCodec(legacyAminoCodec) + mb.RegisterInterfaces(interfaceRegistry) + + return &SigningFixture{ + txConfig: txConfig, + legacy: legacyAminoCodec, + options: options, + protoCodec: protoCodec, + registry: interfaceRegistry, + } +} + +func (s *SigningFixture) RequireLegacyAminoEquivalent(t *testing.T, msg transaction.Msg) { + t.Helper() + // create tx envelope + txBuilder := s.txConfig.NewTxBuilder() + err := txBuilder.SetMsgs([]types.Msg{msg}...) + require.NoError(t, err) + builtTx := txBuilder.GetTx() + + // round trip it to simulate application usage + txBz, err := s.txConfig.TxEncoder()(builtTx) + require.NoError(t, err) + theTx, err := s.txConfig.TxDecoder()(txBz) + require.NoError(t, err) + + // create signing envelope + signerData := signing.SignerData{ + Address: "sender-address", + ChainID: "test-chain", + AccountNumber: 0, + Sequence: 0, + } + adaptableTx, ok := theTx.(authsigning.V2AdaptableTx) + require.True(t, ok) + + legacytx.RegressionTestingAminoCodec = s.legacy + defer func() { + legacytx.RegressionTestingAminoCodec = nil + }() + legacyAminoSignHandler := tx.NewSignModeLegacyAminoJSONHandler() + legacyBz, err := legacyAminoSignHandler.GetSignBytes( + signingtypes.SignMode_SIGN_MODE_LEGACY_AMINO_JSON, + authsigning.SignerData{ + ChainID: signerData.ChainID, + Address: signerData.Address, + AccountNumber: signerData.AccountNumber, + Sequence: signerData.Sequence, + }, + theTx) + require.NoError(t, err) + + handler := aminojson.NewSignModeHandler(aminojson.SignModeHandlerOptions{}) + signBz, err := handler.GetSignBytes( + context.Background(), + signerData, + adaptableTx.GetSigningTxData(), + ) + require.NoError(t, err) + + require.Truef(t, + bytes.Equal(legacyBz, signBz), + "legacy: %s\n x/tx: %s", string(legacyBz), string(signBz)) +} + +func (s *SigningFixture) MarshalLegacyAminoJSON(t *testing.T, o any) []byte { + t.Helper() + bz, err := s.legacy.MarshalJSON(o) + require.NoError(t, err) + if s.options.DoNotSortFields { + return bz + } + sortedBz, err := sortJson(bz) + require.NoError(t, err) + return sortedBz +} + +func (s *SigningFixture) UnmarshalGogoProto(bz []byte, ptr transaction.Msg) error { + return s.protoCodec.Unmarshal(bz, ptr) +} + +func (s *SigningFixture) MessageDescriptor(t *testing.T, msg transaction.Msg) protoreflect.MessageDescriptor { + t.Helper() + typeName := gogoproto.MessageName(msg) + msgDesc, err := s.registry.FindDescriptorByName(protoreflect.FullName(typeName)) + require.NoError(t, err) + return msgDesc.(protoreflect.MessageDescriptor) +} + +// DynamicMessage is identical to the Decoder implementation in +// https://github.com/cosmos/cosmos-sdk/blob/6d2f6ff068c81c5783e01319beaa51c7dbb43edd/x/tx/decode/decode.go#L136 +// It is duplicated here to test dynamic message implementations specifically. +// The code path linked above is also covered in this package. +func (s *SigningFixture) DynamicMessage(t *testing.T, msg transaction.Msg) proto.Message { + t.Helper() + msgDesc := s.MessageDescriptor(t, msg) + protoBz, err := gogoproto.Marshal(msg) + require.NoError(t, err) + dynamicMsg := dynamicpb.NewMessageType(msgDesc).New().Interface() + err = proto.Unmarshal(protoBz, dynamicMsg) + require.NoError(t, err) + return dynamicMsg +} + +// sortJson sorts the JSON bytes by way of the side effect of unmarshalling and remarshalling +// the JSON using encoding/json. This hacky way of sorting JSON fields was used by the legacy +// amino JSON encoding x/auth/migrations/legacytx.StdSignBytes. It is used here ensure the x/tx +// JSON encoding is equivalent to the legacy amino JSON encoding. +func sortJson(bz []byte) ([]byte, error) { + var c any + err := json.Unmarshal(bz, &c) + if err != nil { + return nil, err + } + js, err := json.Marshal(c) + if err != nil { + return nil, err + } + return js, nil +} diff --git a/tests/systemtests/authz_test.go b/tests/systemtests/authz_test.go index c411ad20d36e..da66aef5d267 100644 --- a/tests/systemtests/authz_test.go +++ b/tests/systemtests/authz_test.go @@ -4,6 +4,7 @@ package systemtests import ( "fmt" + "net/http" "os" "testing" "time" @@ -670,73 +671,84 @@ func TestAuthzGRPCQueries(t *testing.T) { invalidMsgTypeOutput := `{"code":2, "message":"codespace authz code 2: authorization not found: authorization not found for invalidMsg type", "details":[]}` expGrantOutput := fmt.Sprintf(`{"grants":[{%s}],"pagination":null}`, grant1) - grantTestCases := []GRPCTestCase{ + grantTestCases := []RestTestCase{ { "invalid granter address", fmt.Sprintf(grantURL, "invalid_granter", grantee1Addr, msgSendTypeURL), + http.StatusInternalServerError, bech32FailOutput, }, { "invalid grantee address", fmt.Sprintf(grantURL, granterAddr, "invalid_grantee", msgSendTypeURL), + http.StatusInternalServerError, bech32FailOutput, }, { "with empty granter", fmt.Sprintf(grantURL, "", grantee1Addr, msgSendTypeURL), + http.StatusInternalServerError, emptyStrOutput, }, { "with empty grantee", fmt.Sprintf(grantURL, granterAddr, "", msgSendTypeURL), + http.StatusInternalServerError, emptyStrOutput, }, { "invalid msg-type", fmt.Sprintf(grantURL, granterAddr, grantee1Addr, "invalidMsg"), + http.StatusInternalServerError, invalidMsgTypeOutput, }, { "valid grant query", fmt.Sprintf(grantURL, granterAddr, grantee1Addr, msgSendTypeURL), + http.StatusOK, expGrantOutput, }, } - RunGRPCQueries(t, grantTestCases) + RunRestQueries(t, grantTestCases) // test query grants grpc endpoint grantsURL := baseurl + "/cosmos/authz/v1beta1/grants?granter=%s&grantee=%s" - grantsTestCases := []GRPCTestCase{ + grantsTestCases := []RestTestCase{ { "expect single grant", fmt.Sprintf(grantsURL, granterAddr, grantee1Addr), + http.StatusOK, fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"1"}}`, grant1), }, { "expect two grants", fmt.Sprintf(grantsURL, granterAddr, grantee2Addr), + http.StatusOK, fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"2"}}`, grant2, grant3), }, { "expect single grant with pagination", fmt.Sprintf(grantsURL+"&pagination.limit=1", granterAddr, grantee2Addr), + http.StatusOK, fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":"L2Nvc21vcy5nb3YudjEuTXNnVm90ZQ==","total":"0"}}`, grant2), }, { "expect single grant with pagination limit and offset", fmt.Sprintf(grantsURL+"&pagination.limit=1&pagination.offset=1", granterAddr, grantee2Addr), + http.StatusOK, fmt.Sprintf(`{"grants":[{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant3), }, { "expect two grants with pagination", fmt.Sprintf(grantsURL+"&pagination.limit=2", granterAddr, grantee2Addr), + http.StatusOK, fmt.Sprintf(`{"grants":[{%s},{%s}],"pagination":{"next_key":null,"total":"0"}}`, grant2, grant3), }, } - RunGRPCQueries(t, grantsTestCases) + RunRestQueries(t, grantsTestCases) // test query grants by granter grpc endpoint grantsByGranterURL := baseurl + "/cosmos/authz/v1beta1/grants/granter/%s" @@ -745,49 +757,55 @@ func TestAuthzGRPCQueries(t *testing.T) { granterQueryOutput := fmt.Sprintf(`{"grants":[{"granter":"%s","grantee":"%s",%s}],"pagination":{"next_key":null,"total":"1"}}`, grantee1Addr, grantee2Addr, grant4) - granterTestCases := []GRPCTestCase{ + granterTestCases := []RestTestCase{ { "invalid granter account address", fmt.Sprintf(grantsByGranterURL, "invalid address"), + http.StatusInternalServerError, decodingFailedOutput, }, { "no authorizations found from granter", fmt.Sprintf(grantsByGranterURL, grantee2Addr), + http.StatusOK, noAuthorizationsOutput, }, { "valid granter query", fmt.Sprintf(grantsByGranterURL, grantee1Addr), + http.StatusOK, granterQueryOutput, }, } - RunGRPCQueries(t, granterTestCases) + RunRestQueries(t, granterTestCases) // test query grants by grantee grpc endpoint grantsByGranteeURL := baseurl + "/cosmos/authz/v1beta1/grants/grantee/%s" grantee1GrantsOutput := fmt.Sprintf(`{"grants":[{"granter":"%s","grantee":"%s",%s}],"pagination":{"next_key":null,"total":"1"}}`, granterAddr, grantee1Addr, grant1) - granteeTestCases := []GRPCTestCase{ + granteeTestCases := []RestTestCase{ { "invalid grantee account address", fmt.Sprintf(grantsByGranteeURL, "invalid address"), + http.StatusInternalServerError, decodingFailedOutput, }, { "no authorizations found from grantee", fmt.Sprintf(grantsByGranteeURL, granterAddr), + http.StatusOK, noAuthorizationsOutput, }, { "valid grantee query", fmt.Sprintf(grantsByGranteeURL, grantee1Addr), + http.StatusOK, grantee1GrantsOutput, }, } - RunGRPCQueries(t, granteeTestCases) + RunRestQueries(t, granteeTestCases) } func setupChain(t *testing.T) (*CLIWrapper, string, string) { diff --git a/tests/systemtests/bank_test.go b/tests/systemtests/bank_test.go index 255e4bae9662..d776bc06a874 100644 --- a/tests/systemtests/bank_test.go +++ b/tests/systemtests/bank_test.go @@ -4,15 +4,13 @@ package systemtests import ( "fmt" + "net/http" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" "github.com/tidwall/sjson" - - "github.com/cosmos/cosmos-sdk/testutil" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) func TestBankSendTxCmd(t *testing.T) { @@ -53,7 +51,7 @@ func TestBankSendTxCmd(t *testing.T) { insufficientCmdArgs = append(insufficientCmdArgs, fmt.Sprintf("%d%s", valBalance, denom), "--fees=10stake") rsp = cli.Run(insufficientCmdArgs...) RequireTxFailure(t, rsp) - require.Contains(t, rsp, sdkerrors.ErrInsufficientFunds.Error()) + require.Contains(t, rsp, "insufficient funds") // test tx bank send with unauthorized signature assertUnauthorizedErr := func(_ assert.TestingT, gotErr error, gotOutputs ...interface{}) bool { @@ -234,10 +232,11 @@ func TestBankGRPCQueries(t *testing.T) { blockHeight := sut.CurrentHeight() supplyTestCases := []struct { - name string - url string - headers map[string]string - expOut string + name string + url string + headers map[string]string + expHttpCode int + expOut string }{ { "test GRPC total supply", @@ -245,12 +244,14 @@ func TestBankGRPCQueries(t *testing.T) { map[string]string{ blockHeightHeader: fmt.Sprintf("%d", blockHeight), }, + http.StatusOK, expTotalSupplyOutput, }, { "test GRPC total supply of a specific denom", supplyUrl + "/by_denom?denom=" + newDenom, map[string]string{}, + http.StatusOK, specificDenomOutput, }, { @@ -259,67 +260,75 @@ func TestBankGRPCQueries(t *testing.T) { map[string]string{ blockHeightHeader: fmt.Sprintf("%d", blockHeight+5), }, + http.StatusInternalServerError, "invalid height", }, { "test GRPC total supply of a bogus denom", supplyUrl + "/by_denom?denom=foobar", map[string]string{}, + http.StatusOK, + // http.StatusNotFound, bogusDenomOutput, }, } for _, tc := range supplyTestCases { t.Run(tc.name, func(t *testing.T) { - resp, err := testutil.GetRequestWithHeaders(tc.url, tc.headers) - require.NoError(t, err) + resp := GetRequestWithHeaders(t, tc.url, tc.headers, tc.expHttpCode) require.Contains(t, string(resp), tc.expOut) }) } // test denom metadata endpoint denomMetadataUrl := baseurl + "/cosmos/bank/v1beta1/denoms_metadata" - dmTestCases := []GRPCTestCase{ + dmTestCases := []RestTestCase{ { "test GRPC client metadata", denomMetadataUrl, + http.StatusOK, fmt.Sprintf(`{"metadatas":%s,"pagination":{"next_key":null,"total":"2"}}`, bankDenomMetadata), }, { "test GRPC client metadata of a specific denom", denomMetadataUrl + "/uatom", + http.StatusOK, fmt.Sprintf(`{"metadata":%s}`, atomDenomMetadata), }, { "test GRPC client metadata of a bogus denom", denomMetadataUrl + "/foobar", + http.StatusNotFound, `{"code":5, "message":"client metadata for denom foobar", "details":[]}`, }, } - RunGRPCQueries(t, dmTestCases) + RunRestQueries(t, dmTestCases) // test bank balances endpoint balanceUrl := baseurl + "/cosmos/bank/v1beta1/balances/" allBalancesOutput := `{"balances":[` + specificDenomOutput + `,{"denom":"stake","amount":"10000000"}],"pagination":{"next_key":null,"total":"2"}}` - balanceTestCases := []GRPCTestCase{ + balanceTestCases := []RestTestCase{ { "test GRPC total account balance", balanceUrl + account1Addr, + http.StatusOK, allBalancesOutput, }, { "test GRPC account balance of a specific denom", fmt.Sprintf("%s%s/by_denom?denom=%s", balanceUrl, account1Addr, newDenom), + http.StatusOK, fmt.Sprintf(`{"balance":%s}`, specificDenomOutput), }, { "test GRPC account balance of a bogus denom", fmt.Sprintf("%s%s/by_denom?denom=foobar", balanceUrl, account1Addr), + http.StatusOK, fmt.Sprintf(`{"balance":%s}`, bogusDenomOutput), }, } - RunGRPCQueries(t, balanceTestCases) + RunRestQueries(t, balanceTestCases) } diff --git a/tests/systemtests/bankv2_test.go b/tests/systemtests/bankv2_test.go index 275b50161f51..b753ee0be430 100644 --- a/tests/systemtests/bankv2_test.go +++ b/tests/systemtests/bankv2_test.go @@ -50,10 +50,9 @@ func TestBankV2SendTxCmd(t *testing.T) { valBalanceAfer := gjson.Get(valRaw, "balance.amount").Int() // TODO: Make DeductFee ante handler work with bank/v2 - require.Equal(t, valBalanceAfer, valBalance - transferAmount) + require.Equal(t, valBalanceAfer, valBalance-transferAmount) receiverRaw := cli.CustomQuery("q", "bankv2", "balance", receiverAddr, denom) receiverBalance := gjson.Get(receiverRaw, "balance.amount").Int() require.Equal(t, receiverBalance, transferAmount) - } diff --git a/tests/systemtests/cometbft_client_test.go b/tests/systemtests/cometbft_client_test.go index e031ae0c8f55..0c9fd62bb5bd 100644 --- a/tests/systemtests/cometbft_client_test.go +++ b/tests/systemtests/cometbft_client_test.go @@ -5,6 +5,7 @@ package systemtests import ( "context" "fmt" + "net/url" "testing" "time" @@ -15,7 +16,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" - "github.com/cosmos/cosmos-sdk/testutil" qtypes "github.com/cosmos/cosmos-sdk/types/query" ) @@ -32,7 +32,7 @@ func TestQueryNodeInfo(t *testing.T) { assert.Equal(t, res.ApplicationVersion.Version, v) // TODO: we should be adding a way to distinguish a v2. Eventually we should skip some v2 system depending on the consensus engine we want to test - restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/node_info", baseurl)) + restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/node_info"))) assert.NoError(t, err) assert.Equal(t, gjson.GetBytes(restRes, "application_version.version").String(), res.ApplicationVersion.Version) } @@ -46,8 +46,7 @@ func TestQuerySyncing(t *testing.T) { res, err := qc.GetSyncing(context.Background(), &cmtservice.GetSyncingRequest{}) assert.NoError(t, err) - restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/syncing", baseurl)) - assert.NoError(t, err) + restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/syncing"))) assert.Equal(t, gjson.GetBytes(restRes, "syncing").Bool(), res.Syncing) } @@ -61,8 +60,7 @@ func TestQueryLatestBlock(t *testing.T) { assert.NoError(t, err) assert.Contains(t, res.SdkBlock.Header.ProposerAddress, "cosmosvalcons") - _, err = testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/latest", baseurl)) - assert.NoError(t, err) + _ = GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/blocks/latest"))) } func TestQueryBlockByHeight(t *testing.T) { @@ -78,8 +76,7 @@ func TestQueryBlockByHeight(t *testing.T) { assert.Equal(t, res.SdkBlock.Header.Height, int64(2)) assert.Contains(t, res.SdkBlock.Header.ProposerAddress, "cosmosvalcons") - restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/blocks/%d", baseurl, 2)) - assert.NoError(t, err) + restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/blocks/2"))) assert.Equal(t, gjson.GetBytes(restRes, "sdk_block.header.height").Int(), int64(2)) assert.Contains(t, gjson.GetBytes(restRes, "sdk_block.header.proposer_address").String(), "cosmosvalcons") } @@ -106,8 +103,7 @@ func TestQueryLatestValidatorSet(t *testing.T) { assert.NoError(t, err) assert.Equal(t, len(res.Validators), 2) - restRes, err := testutil.GetRequest(fmt.Sprintf("%s/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=%d&pagination.limit=%d", baseurl, 0, 2)) - assert.NoError(t, err) + restRes := GetRequest(t, mustV(url.JoinPath(baseurl, "/cosmos/base/tendermint/v1beta1/validatorsets/latest?pagination.offset=0&pagination.limit=2"))) assert.Equal(t, len(gjson.GetBytes(restRes, "validators").Array()), 2) } @@ -144,6 +140,7 @@ func TestLatestValidatorSet(t *testing.T) { }) } } + func TestLatestValidatorSet_GRPCGateway(t *testing.T) { sut.ResetChain(t) sut.StartChain(t) @@ -164,8 +161,7 @@ func TestLatestValidatorSet_GRPCGateway(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - rsp, err := testutil.GetRequest(fmt.Sprintf("%s%s", baseurl, tc.url)) - assert.NoError(t, err) + rsp := GetRequest(t, mustV(url.JoinPath(baseurl, tc.url))) if tc.expErr { errMsg := gjson.GetBytes(rsp, "message").String() assert.Contains(t, errMsg, tc.expErrMsg) @@ -230,8 +226,7 @@ func TestValidatorSetByHeight_GRPCGateway(t *testing.T) { } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - rsp, err := testutil.GetRequest(tc.url) - assert.NoError(t, err) + rsp := GetRequest(t, tc.url) if tc.expErr { errMsg := gjson.GetBytes(rsp, "message").String() assert.Contains(t, errMsg, tc.expErrMsg) diff --git a/tests/systemtests/fraud_test.go b/tests/systemtests/fraud_test.go index 043db59a545e..0479f526cc2d 100644 --- a/tests/systemtests/fraud_test.go +++ b/tests/systemtests/fraud_test.go @@ -35,8 +35,7 @@ func TestValidatorDoubleSign(t *testing.T) { newNode := sut.AddFullnode(t, func(nodeNumber int, nodePath string) { valKeyFile := filepath.Join(WorkDir, nodePath, "config", "priv_validator_key.json") _ = os.Remove(valKeyFile) - _, err := copyFile(filepath.Join(WorkDir, sut.nodePath(0), "config", "priv_validator_key.json"), valKeyFile) - require.NoError(t, err) + _ = MustCopyFile(filepath.Join(WorkDir, sut.nodePath(0), "config", "priv_validator_key.json"), valKeyFile) }) sut.AwaitNodeUp(t, fmt.Sprintf("http://%s:%d", newNode.IP, newNode.RPCPort)) diff --git a/tests/systemtests/go.mod b/tests/systemtests/go.mod index 994a694a232c..6203d6d05d05 100644 --- a/tests/systemtests/go.mod +++ b/tests/systemtests/go.mod @@ -125,7 +125,7 @@ require ( github.com/petermattis/goid v0.0.0-20231207134359-e60b3f734c67 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/tests/systemtests/go.sum b/tests/systemtests/go.sum index c65faad332b6..746009230523 100644 --- a/tests/systemtests/go.sum +++ b/tests/systemtests/go.sum @@ -617,8 +617,8 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2 github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= diff --git a/tests/systemtests/gov_test.go b/tests/systemtests/gov_test.go index 73bc7fd96efc..092773dc2053 100644 --- a/tests/systemtests/gov_test.go +++ b/tests/systemtests/gov_test.go @@ -8,13 +8,14 @@ import ( "testing" "time" - "cosmossdk.io/math" - "github.com/cosmos/cosmos-sdk/client/flags" - "github.com/cosmos/cosmos-sdk/testutil" - sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tidwall/gjson" + + "cosmossdk.io/math" + + "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" ) func TestSubmitProposal(t *testing.T) { @@ -39,7 +40,8 @@ func TestSubmitProposal(t *testing.T) { "type": "Text", "deposit": "-324foocoin" }` - invalidPropFile := testutil.WriteToNewTempFile(t, invalidProp) + + invalidPropFile := StoreTempFile(t, []byte(invalidProp)) defer invalidPropFile.Close() // Create a valid new proposal JSON. @@ -62,7 +64,7 @@ func TestSubmitProposal(t *testing.T) { "metadata": "%s", "deposit": "%s" }`, govAddress, base64.StdEncoding.EncodeToString(propMetadata), sdk.NewCoin("stake", math.NewInt(100000))) - validPropFile := testutil.WriteToNewTempFile(t, validProp) + validPropFile := StoreTempFile(t, []byte(validProp)) defer validPropFile.Close() testCases := []struct { @@ -136,7 +138,7 @@ func TestSubmitLegacyProposal(t *testing.T) { "type": "Text", "deposit": "-324foocoin" }` - invalidPropFile := testutil.WriteToNewTempFile(t, invalidProp) + invalidPropFile := StoreTempFile(t, []byte(invalidProp)) defer invalidPropFile.Close() validProp := fmt.Sprintf(`{ @@ -145,7 +147,7 @@ func TestSubmitLegacyProposal(t *testing.T) { "type": "Text", "deposit": "%s" }`, sdk.NewCoin("stake", math.NewInt(154310))) - validPropFile := testutil.WriteToNewTempFile(t, validProp) + validPropFile := StoreTempFile(t, []byte(validProp)) defer validPropFile.Close() testCases := []struct { @@ -253,7 +255,8 @@ func TestNewCmdWeightedVote(t *testing.T) { fmt.Sprintf("--%s=%s", flags.FlagFrom, valAddr), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String())} + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()), + } rsp := cli.Run(proposalArgs...) txResult, found := cli.AwaitTxCommitted(rsp) require.True(t, found) @@ -389,7 +392,8 @@ func TestQueryDeposit(t *testing.T) { fmt.Sprintf("--%s=%s", flags.FlagFrom, valAddr), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastSync), - fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String())} + fmt.Sprintf("--%s=%s", flags.FlagFees, sdk.NewCoins(sdk.NewCoin("stake", math.NewInt(10))).String()), + } rsp := cli.Run(proposalArgs...) txResult, found := cli.AwaitTxCommitted(rsp) require.True(t, found) diff --git a/tests/systemtests/io_utils.go b/tests/systemtests/io_utils.go new file mode 100644 index 000000000000..a9cd1094fba6 --- /dev/null +++ b/tests/systemtests/io_utils.go @@ -0,0 +1,65 @@ +package systemtests + +import ( + "bytes" + "fmt" + "io" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/require" +) + +// MustCopyFile copies the file from the source path `src` to the destination path `dest` and returns an open file handle to `dest`. +func MustCopyFile(src, dest string) *os.File { + in, err := os.Open(src) + if err != nil { + panic(fmt.Sprintf("failed to open %q: %v", src, err)) + } + defer in.Close() + + out, err := os.Create(dest) + if err != nil { + panic(fmt.Sprintf("failed to create %q: %v", dest, err)) + } + defer out.Close() + + _, err = io.Copy(out, in) + if err != nil { + panic(fmt.Sprintf("failed to copy from %q to %q: %v", src, dest, err)) + } + return out +} + +// MustCopyFilesInDir copies all files (excluding directories) from the source directory `src` to the destination directory `dest`. +func MustCopyFilesInDir(src, dest string) { + err := os.MkdirAll(dest, 0o750) + if err != nil { + panic(fmt.Sprintf("failed to create %q: %v", dest, err)) + } + + fs, err := os.ReadDir(src) + if err != nil { + panic(fmt.Sprintf("failed to read dir %q: %v", src, err)) + } + + for _, f := range fs { + if f.IsDir() { + continue + } + _ = MustCopyFile(filepath.Join(src, f.Name()), filepath.Join(dest, f.Name())) + } +} + +// StoreTempFile creates a temporary file in the test's temporary directory with the provided content. +// It returns a pointer to the created file. Errors during the process are handled with test assertions. +func StoreTempFile(t *testing.T, content []byte) *os.File { + t.Helper() + out, err := os.CreateTemp(t.TempDir(), "") + require.NoError(t, err) + _, err = io.Copy(out, bytes.NewReader(content)) + require.NoError(t, err) + require.NoError(t, out.Close()) + return out +} diff --git a/tests/systemtests/rest_cli.go b/tests/systemtests/rest_cli.go index c53533c0786f..2ae879e1a242 100644 --- a/tests/systemtests/rest_cli.go +++ b/tests/systemtests/rest_cli.go @@ -1,29 +1,56 @@ package systemtests import ( + "io" + "net/http" "testing" "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/testutil" ) -type GRPCTestCase struct { - name string - url string - expOut string +type RestTestCase struct { + name string + url string + expCode int + expOut string } -// RunGRPCQueries runs given grpc testcases by making requests and +// RunRestQueries runs given Rest testcases by making requests and // checking response with expected output -func RunGRPCQueries(t *testing.T, testCases []GRPCTestCase) { +func RunRestQueries(t *testing.T, testCases []RestTestCase) { t.Helper() for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - resp, err := testutil.GetRequest(tc.url) - require.NoError(t, err) + resp := GetRequestWithHeaders(t, tc.url, nil, tc.expCode) require.JSONEq(t, tc.expOut, string(resp)) }) } } + +func GetRequest(t *testing.T, url string) []byte { + t.Helper() + return GetRequestWithHeaders(t, url, nil, http.StatusOK) +} + +func GetRequestWithHeaders(t *testing.T, url string, headers map[string]string, expCode int) []byte { + t.Helper() + req, err := http.NewRequest("GET", url, nil) + require.NoError(t, err) + + for key, value := range headers { + req.Header.Set(key, value) + } + + httpClient := &http.Client{} + res, err := httpClient.Do(req) + require.NoError(t, err) + defer func() { + _ = res.Body.Close() + }() + require.Equal(t, expCode, res.StatusCode, "status code should be %d, got: %d", expCode, res.StatusCode) + + body, err := io.ReadAll(res.Body) + require.NoError(t, err) + return body +} diff --git a/tests/systemtests/snapshots_test.go b/tests/systemtests/snapshots_test.go index 42569a031799..d80eb530f413 100644 --- a/tests/systemtests/snapshots_test.go +++ b/tests/systemtests/snapshots_test.go @@ -4,13 +4,13 @@ package systemtests import ( "fmt" - "github.com/stretchr/testify/require" "os" "testing" + + "github.com/stretchr/testify/require" ) func TestSnapshots(t *testing.T) { - sut.ResetChain(t) cli := NewCLIWrapper(t, sut, verbose) sut.StartChain(t) diff --git a/tests/systemtests/system.go b/tests/systemtests/system.go index c4368c01558a..7aa00f7cfbf3 100644 --- a/tests/systemtests/system.go +++ b/tests/systemtests/system.go @@ -147,15 +147,11 @@ func (s *SystemUnderTest) SetupChain() { // backup genesis dest := filepath.Join(WorkDir, s.nodePath(0), "config", "genesis.json.orig") - if _, err := copyFile(src, dest); err != nil { - panic(fmt.Sprintf("copy failed :%#+v", err)) - } + MustCopyFile(src, dest) // backup keyring src = filepath.Join(WorkDir, s.nodePath(0), "keyring-test") dest = filepath.Join(WorkDir, s.outputDir, "keyring-test") - if err := copyFilesInDir(src, dest); err != nil { - panic(fmt.Sprintf("copy files from dir :%#+v", err)) - } + MustCopyFilesInDir(src, dest) } func (s *SystemUnderTest) StartChain(t *testing.T, xargs ...string) { @@ -485,7 +481,7 @@ func (s *SystemUnderTest) modifyGenesisJSON(t *testing.T, mutators ...GenesisMut for _, m := range mutators { current = m(current) } - out := storeTempFile(t, current) + out := StoreTempFile(t, current) defer os.Remove(out.Name()) s.setGenesis(t, out.Name()) s.MarkDirty() @@ -712,8 +708,7 @@ func (s *SystemUnderTest) AddFullnode(t *testing.T, beforeStart ...func(nodeNumb for _, tomlFile := range []string{"config.toml", "app.toml"} { configFile := filepath.Join(configPath, tomlFile) _ = os.Remove(configFile) - _, err := copyFile(filepath.Join(WorkDir, s.nodePath(0), "config", tomlFile), configFile) - require.NoError(t, err) + _ = MustCopyFile(filepath.Join(WorkDir, s.nodePath(0), "config", tomlFile), configFile) } // start node allNodes := s.AllNodes(t) @@ -949,54 +944,6 @@ func restoreOriginalKeyring(t *testing.T, s *SystemUnderTest) { require.NoError(t, os.RemoveAll(dest)) for i := 0; i < s.initialNodesCount; i++ { src := filepath.Join(WorkDir, s.nodePath(i), "keyring-test") - require.NoError(t, copyFilesInDir(src, dest)) - } -} - -// copyFile copy source file to dest file path -func copyFile(src, dest string) (*os.File, error) { - in, err := os.Open(src) - if err != nil { - return nil, err + MustCopyFilesInDir(src, dest) } - defer in.Close() - out, err := os.Create(dest) - if err != nil { - return nil, err - } - defer out.Close() - - _, err = io.Copy(out, in) - return out, err -} - -// copyFilesInDir copy files in src dir to dest path -func copyFilesInDir(src, dest string) error { - err := os.MkdirAll(dest, 0o750) - if err != nil { - return fmt.Errorf("mkdirs: %w", err) - } - fs, err := os.ReadDir(src) - if err != nil { - return fmt.Errorf("read dir: %w", err) - } - for _, f := range fs { - if f.IsDir() { - continue - } - if _, err := copyFile(filepath.Join(src, f.Name()), filepath.Join(dest, f.Name())); err != nil { - return fmt.Errorf("copy file: %q: %w", f.Name(), err) - } - } - return nil -} - -func storeTempFile(t *testing.T, content []byte) *os.File { - t.Helper() - out, err := os.CreateTemp(t.TempDir(), "genesis") - require.NoError(t, err) - _, err = io.Copy(out, bytes.NewReader(content)) - require.NoError(t, err) - require.NoError(t, out.Close()) - return out } diff --git a/tools/confix/README.md b/tools/confix/README.md index 64b2f49b3dc7..00851ede1923 100644 --- a/tools/confix/README.md +++ b/tools/confix/README.md @@ -23,7 +23,7 @@ import "cosmossdk.io/tools/confix/cmd" Find the following line: ```go -initRootCmd(rootCmd, encodingConfig) +initRootCmd(rootCmd, moduleManager) ``` After that line, add the following: @@ -39,10 +39,10 @@ An implementation example can be found in `simapp`. The command will be available as `simd config`. -```tip +:::tip Using confix directly in the application can have less features than using it standalone. This is because confix is versioned with the SDK, while `latest` is the standalone version. -``` +::: ### Using Confix Standalone @@ -138,7 +138,7 @@ confix view ~/.simapp/config/client.toml # views the current app client conf ### Maintainer -At each SDK modification of the default configuration, add the default SDK config under `data/v0.XX-app.toml`. +At each SDK modification of the default configuration, add the default SDK config under `data/vXX-app.toml`. This allows users to use the tool standalone. ### Compatibility @@ -149,7 +149,8 @@ The recommended standalone version is `latest`, which is using the latest develo | ----------- | -------------- | | v0.50 | v0.1.x | | v0.52 | v0.2.x | +| v2 | v0.2.x | ## Credits -This project is based on the [CometBFT RFC 019](https://github.com/cometbft/cometbft/blob/5013bc3f4a6d64dcc2bf02ccc002ebc9881c62e4/docs/rfc/rfc-019-config-version.md) and their own implementation of [confix](https://github.com/cometbft/cometbft/blob/v0.36.x/scripts/confix/confix.go). +This project is based on the [CometBFT RFC 019](https://github.com/cometbft/cometbft/blob/5013bc3f4a6d64dcc2bf02ccc002ebc9881c62e4/docs/rfc/rfc-019-config-version.md) and their never released own implementation of [confix](https://github.com/cometbft/cometbft/blob/v0.36.x/scripts/confix/confix.go). diff --git a/tools/confix/go.mod b/tools/confix/go.mod index c5b1fd42201f..e6800c66e46b 100644 --- a/tools/confix/go.mod +++ b/tools/confix/go.mod @@ -117,7 +117,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/tools/confix/go.sum b/tools/confix/go.sum index ac4e68a5bd46..32242dcba2a9 100644 --- a/tools/confix/go.sum +++ b/tools/confix/go.sum @@ -618,8 +618,8 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2 github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= diff --git a/tools/cosmovisor/README.md b/tools/cosmovisor/README.md index e726239a8969..3b5f722c5d1b 100644 --- a/tools/cosmovisor/README.md +++ b/tools/cosmovisor/README.md @@ -7,22 +7,21 @@ sidebar_position: 1 `cosmovisor` is a process manager for Cosmos SDK application binaries that automates application binary switch at chain upgrades. It polls the `upgrade-info.json` file that is created by the x/upgrade module at upgrade height, and then can automatically download the new binary, stop the current binary, switch from the old binary to the new one, and finally restart the node with the new binary. -* [Cosmovisor](#cosmovisor) - * [Design](#design) - * [Contributing](#contributing) - * [Setup](#setup) +* [Design](#design) +* [Contributing](#contributing) +* [Setup](#setup) * [Installation](#installation) * [Command Line Arguments And Environment Variables](#command-line-arguments-and-environment-variables) * [Folder Layout](#folder-layout) - * [Usage](#usage) +* [Usage](#usage) * [Initialization](#initialization) * [Detecting Upgrades](#detecting-upgrades) * [Adding Upgrade Binary](#adding-upgrade-binary) - * [Preparing for an Upgrade](#preparing-for-an-upgrade) * [Auto-Download](#auto-download) - * [Example: SimApp Upgrade](#example-simapp-upgrade) + * [Preparing for an Upgrade](#preparing-for-an-upgrade) +* [Example: SimApp Upgrade](#example-simapp-upgrade) * [Chain Setup](#chain-setup) - * [Prepare Cosmovisor and Start the Chain](#prepare-cosmovisor-and-start-the-chain) + * [Prepare Cosmovisor and Start the Chain](#prepare-cosmovisor-and-start-the-chain) * [Update App](#update-app) ## Design diff --git a/tools/cosmovisor/go.mod b/tools/cosmovisor/go.mod index aa82e5fec908..d4b7d5328069 100644 --- a/tools/cosmovisor/go.mod +++ b/tools/cosmovisor/go.mod @@ -135,7 +135,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect @@ -166,7 +166,7 @@ require ( golang.org/x/crypto v0.27.0 // indirect golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/tools/cosmovisor/go.sum b/tools/cosmovisor/go.sum index b91d25273f8a..0fdc70f990e7 100644 --- a/tools/cosmovisor/go.sum +++ b/tools/cosmovisor/go.sum @@ -854,8 +854,8 @@ github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt2 github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo= github.com/prometheus/common v0.15.0/go.mod h1:U+gB1OBLb1lF3O42bTCL+FK18tX9Oar16Clt/msog/s= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= @@ -1142,8 +1142,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= diff --git a/tools/cosmovisor/testdata/download/cosmovisor/genesis/bin/autod b/tools/cosmovisor/testdata/download/cosmovisor/genesis/bin/autod index c1b2348787ae..c8d7e1e30fa7 100755 --- a/tools/cosmovisor/testdata/download/cosmovisor/genesis/bin/autod +++ b/tools/cosmovisor/testdata/download/cosmovisor/genesis/bin/autod @@ -10,7 +10,7 @@ cat > "$3" < "$3" < amount:`, + }, + { + "many", + types.Periods{ + {Length: int64(12 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 500), sdk.NewInt64Coin(stakeDenom, 50)}}, + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 250), sdk.NewInt64Coin(stakeDenom, 25)}}, + {Length: int64(6 * 60 * 60), Amount: sdk.Coins{sdk.NewInt64Coin(feeDenom, 100), sdk.NewInt64Coin(stakeDenom, 15)}}, + }, + "Vesting Periods:\n\t\t" + `length:43200 amount: amount: , ` + + `length:21600 amount: amount: , ` + + `length:21600 amount: amount:`, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.periods.String() + if got != tt.want { + t.Fatalf("Mismatch in values:\n\tGot: %q\n\tWant: %q", got, tt.want) + } + }) + } +} diff --git a/x/authz/README.md b/x/authz/README.md index c4752c2eddc6..405bd5427e6a 100644 --- a/x/authz/README.md +++ b/x/authz/README.md @@ -38,12 +38,12 @@ The `x/authz` module defines interfaces and messages grant authorizations to per on behalf of one account to other accounts. The design is defined in the [ADR 030](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-030-authz-module.md). A *grant* is an allowance to execute a Msg by the grantee on behalf of the granter. -Authorization is an interface that must be implemented by a concrete authorization logic to validate and execute grants. Authorizations are extensible and can be defined for any Msg service method even outside of the module where the Msg method is defined. See the `SendAuthorization` example in the next section for more details. +Authorization is an interface that must be implemented by a concrete authorization logic to validate and execute grants. Authorizations are extensible and can be defined for any Msg service method, even if the Msg method is defined outside of the module. See the `SendAuthorization` example in the next section for more details. -**Note:** The authz module is different from the [auth (authentication)](../modules/auth/) module that is responsible for specifying the base transaction and account types. +**Note:** The authz module is different from the [auth (authentication)](../modules/auth/) module, which is responsible for specifying the base transaction and account types. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/authz/authorizations.go#L11-L25 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/authorizations.go#L14-L28 ``` ### Built-in Authorizations @@ -55,11 +55,11 @@ The Cosmos SDK `x/authz` module comes with following authorization types: `GenericAuthorization` implements the `Authorization` interface that gives unrestricted permission to execute the provided Msg on behalf of granter's account. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/authz/v1beta1/authz.proto#L14-L22 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/authz.proto#L14-L22 ``` ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/authz/generic_authorization.go#L16-L29 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/generic_authorization.go#L18-L34 ``` * `msg` stores Msg type URL. @@ -72,11 +72,11 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/authz/generic_authorizat * It takes an (optional) `AllowList` that specifies to which addresses a grantee can send token. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/authz.proto#L11-L30 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/authz.proto#L11-L29 ``` ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/bank/types/send_authorization.go#L29-L62 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/types/send_authorization.go#L33-L73 ``` * `spend_limit` keeps track of how many coins are left in the authorization. @@ -84,21 +84,21 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/bank/types/send_authoriz #### StakeAuthorization -`StakeAuthorization` implements the `Authorization` interface for messages in the [staking module](https://docs.cosmos.network/main/build/modules/staking). It takes an `AuthorizationType` to specify whether you want to authorise delegating, undelegating or redelegating (i.e. these have to be authorised separately). It also takes an optional `MaxTokens` that keeps track of a limit to the amount of tokens that can be delegated/undelegated/redelegated. If left empty, the amount is unlimited. Additionally, this Msg takes an `AllowList` or a `DenyList`, which allows you to select which validators you allow or deny grantees to stake with. +`StakeAuthorization` implements the `Authorization` interface for messages in the [staking module](https://docs.cosmos.network/main/build/modules/staking). It takes an `AuthorizationType` to specify whether you want to authorize delegation, undelegation, redelegation or cancel unbonding delegation, each of which must be authorized separately. It also takes an optional `MaxTokens` that keeps track of a limit to the amount of tokens that can be delegated/undelegated/redelegated. If left empty, the amount is unlimited. Additionally, this Msg takes an `AllowList` or a `DenyList`, enabling you to specify which validators the grantee can or cannot stake with. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/staking/v1beta1/authz.proto#L11-L35 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/proto/cosmos/staking/v1beta1/authz.proto#L11-L34 ``` ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/staking/types/authz.go#L15-L35 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/types/authz.go#L78-L166 ``` ### Gas -In order to prevent DoS attacks, granting `StakeAuthorization`s with `x/authz` incurs gas. `StakeAuthorization` allows you to authorize another account to delegate, undelegate, or redelegate to validators. The authorizer can define a list of validators they allow or deny delegations to. The Cosmos SDK iterates over these lists and charge 10 gas for each validator in both of the lists. +To prevent DoS attacks, granting `StakeAuthorization`s with `x/authz` incurs gas. `StakeAuthorization` allows you to authorize another account to delegate, undelegate, or redelegate tokens to validators. The granter can define a list of validators for which they allow or deny delegations. The Cosmos SDK then iterates over these lists and charge 10 gas for each validator included in both lists. -Since the state maintaining a list for granter, grantee pair with same expiration, we are iterating over the list to remove the grant (in case of any revoke of particular `msgType`) from the list and we are charging 20 gas per iteration. +Since the state maintains a list of granter-grantee pairs with same expiration, we iterate over this list to remove the grant from the list (in case of any revoke of particular `msgType`), charging 20 gas for each iteration. ## State @@ -111,17 +111,17 @@ Grants are identified by combining granter address (the address bytes of the gra The grant object encapsulates an `Authorization` type and an expiration timestamp: ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/authz/v1beta1/authz.proto#L24-L32 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/authz.proto#L24-L32 ``` ### GrantQueue We are maintaining a queue for authz pruning. Whenever a grant is created, an item will be added to `GrantQueue` with a key of expiration, granter, grantee. -In `EndBlock` (which runs for every block) we continuously check and prune the expired grants by forming a prefix key with current blocktime that passed the stored expiration in `GrantQueue`, we iterate through all the matched records from `GrantQueue` and delete them from the `GrantQueue` & `Grant`s store. +In `EndBlock` (which runs for every block) we continuously check and prune the expired grants by forming a prefix key with current blocktime that passed the stored expiration in `GrantQueue`, we iterate through all the matched records from `GrantQueue` and delete maximum of 200 grants from the `GrantQueue` & `Grant`s store for each run. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/5f4ddc6f80f9707320eec42182184207fff3833a/x/authz/keeper/keeper.go#L378-L403 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/keeper/keeper.go#L479-L520 ``` * GrantQueue: `0x02 | expiration_bytes | granter_address_len (1 byte) | granter_address_bytes | grantee_address_len (1 byte) | grantee_address_bytes -> ProtocolBuffer(GrantQueueItem)` @@ -129,7 +129,7 @@ https://github.com/cosmos/cosmos-sdk/blob/5f4ddc6f80f9707320eec42182184207fff383 The `expiration_bytes` are the expiration date in UTC with the format `"2006-01-02T15:04:05.000000000"`. ```go reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/x/authz/keeper/keys.go#L77-L93 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/keeper/keys.go#L84-L100 ``` The `GrantQueueItem` object contains the list of type urls between granter and grantee that expire at the time indicated in the key. @@ -146,7 +146,7 @@ If there is already a grant for the `(granter, grantee, Authorization)` triple, An authorization grant for authz `MsgGrant` is not allowed and will return an error. This is for preventing user from accidentally authorizing their entire account to a different account. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/authz/v1beta1/tx.proto#L35-L45 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/tx.proto#L45-L55 ``` The message handling should fail if: @@ -161,7 +161,7 @@ The message handling should fail if: A grant can be removed with the `MsgRevoke` message. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/authz/v1beta1/tx.proto#L69-L78 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/tx.proto#L79-L88 ``` The message handling should fail if: @@ -176,7 +176,7 @@ NOTE: The `MsgExec` message removes a grant if the grant has expired. The `MsgRevokeAll` message revokes all grants issued by the specified granter. This is useful for quickly removing all authorizations granted by a single granter without specifying individual message types or grantees. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/tree/main/x/authz/proto/cosmos/authz/v1beta1/tx.proto#L93-L100 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/tx.proto#L93-L100 ``` The message handling should fail if: @@ -189,7 +189,7 @@ The message handling should fail if: When a grantee wants to execute a transaction on behalf of a granter, they must send `MsgExec`. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/authz/v1beta1/tx.proto#L52-L63 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/authz/proto/cosmos/authz/v1beta1/tx.proto#L60-L72 ``` The message handling should fail if: @@ -314,6 +314,20 @@ Example: simd tx authz revoke cosmos1.. /cosmos.bank.v1beta1.MsgSend --from=cosmos1.. ``` +##### revoke-all + +The `revoke-all` command allows a granter to revoke all authorizations created by the granter. + +```bash +simd tx authz revoke-all --from=[granter] [flags] +``` + +Example: + +```bash +simd tx authz revoke-all --from=cosmos1.. +``` + ### gRPC A user can query the `authz` module using gRPC endpoints. @@ -335,27 +349,6 @@ grpcurl -plaintext \ cosmos.authz.v1beta1.Query/Grants ``` -Example Output: - -```bash -{ - "grants": [ - { - "authorization": { - "@type": "/cosmos.bank.v1beta1.SendAuthorization", - "spendLimit": [ - { - "denom":"stake", - "amount":"100" - } - ] - }, - "expiration": "2022-01-01T00:00:00Z" - } - ] -} -``` - ### REST A user can query the `authz` module using REST endpoints. @@ -369,25 +362,3 @@ Example: ```bash curl "localhost:1317/cosmos/authz/v1beta1/grants?granter=cosmos1..&grantee=cosmos1..&msg_type_url=/cosmos.bank.v1beta1.MsgSend" ``` - -Example Output: - -```bash -{ - "grants": [ - { - "authorization": { - "@type": "/cosmos.bank.v1beta1.SendAuthorization", - "spend_limit": [ - { - "denom": "stake", - "amount": "100" - } - ] - }, - "expiration": "2022-01-01T00:00:00Z" - } - ], - "pagination": null -} -``` diff --git a/x/authz/go.mod b/x/authz/go.mod index 4205f0a387b4..a40b44423b98 100644 --- a/x/authz/go.mod +++ b/x/authz/go.mod @@ -119,7 +119,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/authz/go.sum b/x/authz/go.sum index d7ad42cc008f..7588b565a0d7 100644 --- a/x/authz/go.sum +++ b/x/authz/go.sum @@ -412,8 +412,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/bank/CHANGELOG.md b/x/bank/CHANGELOG.md index f226eac88503..7cfd8ed0410b 100644 --- a/x/bank/CHANGELOG.md +++ b/x/bank/CHANGELOG.md @@ -35,13 +35,14 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `SendCoinsFromModuleToAccount`, `SendCoinsFromModuleToModule`, `SendCoinsFromAccountToModule`, `DelegateCoinsFromAccountToModule`, `UndelegateCoinsFromModuleToAccount`, `MintCoins` and `BurnCoins` methods now returns an error instead of panicking if any module accounts does not exist or unauthorized. * [#20517](https://github.com/cosmos/cosmos-sdk/pull/20517) `SendCoins` now checks for `SendRestrictions` before instead of after deducting coins using `subUnlockedCoins`. * [#20354](https://github.com/cosmos/cosmos-sdk/pull/20354) Reduce the number of `ValidateDenom` calls in `bank.SendCoins`. +* [#21976](https://github.com/cosmos/cosmos-sdk/pull/21976) Resolve a footgun by swapping send restrictions check in `InputOutputCoins` before coin deduction. ### Bug Fixes * [#21407](https://github.com/cosmos/cosmos-sdk/pull/21407) Fix handling of negative spendable balances. - * The `SpendableBalances` query now correctly reports spendable balances when one or more denoms are negative (used to report all zeros). Also, this query now looks up only the balances for the requested page. - * The `SpendableCoins` keeper method now returns the positive spendable balances even when one or more denoms have more locked than available (used to return an empty `Coins`). - * The `SpendableCoin` keeper method now returns a zero coin if there's more locked than available (used to return a negative coin). + * The `SpendableBalances` query now correctly reports spendable balances when one or more denoms are negative (used to report all zeros). Also, this query now looks up only the balances for the requested page. + * The `SpendableCoins` keeper method now returns the positive spendable balances even when one or more denoms have more locked than available (used to return an empty `Coins`). + * The `SpendableCoin` keeper method now returns a zero coin if there's more locked than available (used to return a negative coin). ### API Breaking Changes diff --git a/x/bank/README.md b/x/bank/README.md index 5ac389feb5a2..f6f77f1f947e 100644 --- a/x/bank/README.md +++ b/x/bank/README.md @@ -10,15 +10,13 @@ This document specifies the bank module of the Cosmos SDK. The bank module is responsible for handling multi-asset coin transfers between accounts and tracking special-case pseudo-transfers which must work differently -with particular kinds of accounts (notably delegating/undelegating for vesting +with particular kinds of accounts (notably delegating/undelegating for legacy vesting accounts). It exposes several interfaces with varying capabilities for secure interaction with other modules which must alter user balances. In addition, the bank module tracks and provides query support for the total supply of all assets used in the application. -This module is used in the Cosmos Hub. - ## Contents * [Supply](#supply) @@ -51,9 +49,9 @@ The `supply` functionality: ### Total Supply -The total `Supply` of the network is equal to the sum of all coins from the -account. The total supply is updated every time a `Coin` is minted (eg: as part -of the inflation mechanism) or burned (eg: due to slashing or if a governance +The total `Supply` of the network is equal to the sum of all coins from all +accounts within a chain. The total supply is updated every time a `Coin` is minted +(eg: as part of the inflation mechanism) or burned (eg: due to slashing or if a governance proposal is vetoed). ## Module Accounts @@ -83,13 +81,12 @@ type ModuleAccount interface { > **WARNING!** > Any module or message handler that allows either direct or indirect sending of funds must explicitly guarantee those funds cannot be sent to module accounts (unless allowed). -The supply `Keeper` also introduces new wrapper functions for the auth `Keeper` -and the bank `Keeper` that are related to `ModuleAccount`s in order to be able -to: +The supply `Keeper` interface also introduces new wrapper functions for the auth `Keeper` +and the bank `SendKeeper` in order to be able to: -* Get and set `ModuleAccount`s by providing the `Name`. -* Send coins from and to other `ModuleAccount`s or standard `Account`s - (`BaseAccount` or `VestingAccount`) by passing only the `Name`. +* Get `ModuleAccount`s by providing its `Name`. +* Send coins from and to other `ModuleAccount`s by passing only the `Name` or standard `Account`s + (`BaseAccount` or legacy `VestingAccount`). * `Mint` or `Burn` coins for a `ModuleAccount` (restricted to its permissions). ### Permissions @@ -122,6 +119,7 @@ aforementioned state: * Denom Metadata Index: `0x1 | byte(denom) -> ProtocolBuffer(Metadata)` * Balances Index: `0x2 | byte(address length) | []byte(address) | []byte(balance.Denom) -> ProtocolBuffer(balance)` * Reverse Denomination to Address Index: `0x03 | byte(denom) | 0x00 | []byte(address) -> 0` +* Send enabled Denoms: `0x4 | string -> bool` ## Params @@ -131,7 +129,7 @@ it can be updated with governance or the address with authority. * Params: `0x05 | ProtocolBuffer(Params)` ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/bank.proto#L12-L23 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/bank.proto#L12-L23 ``` ## Keepers @@ -142,11 +140,11 @@ should use the least-permissive interface that provides the functionality they require. Best practices dictate careful review of `bank` module code to ensure that -permissions are limited in the way that you expect. +permissions are limited in the way that you expected. ### Denied Addresses -The `x/bank` module accepts a map of addresses that are considered blocklisted +The `x/bank` module accepts a map of addresses (`blockedAddrs`) that are considered blocklisted from directly and explicitly receiving funds through means such as `MsgSend` and `MsgMultiSend` and direct API calls like `SendCoinsFromModuleToAccount`. @@ -160,7 +158,7 @@ By providing the `x/bank` module with a blocklisted set of addresses, an error o #### Input -An input of a multiparty transfer +An input of a multi-send transaction ```protobuf // Input models transaction input. @@ -172,7 +170,7 @@ message Input { #### Output -An output of a multiparty transfer. +An output of a multi-send transaction. ```protobuf // Output models transaction outputs. @@ -195,8 +193,8 @@ type Keeper interface { SendKeeper WithMintCoinsRestriction(MintingRestrictionFn) BaseKeeper - InitGenesis(context.Context, *types.GenesisState) - ExportGenesis(context.Context) *types.GenesisState + InitGenesis(context.Context, *types.GenesisState) error + ExportGenesis(context.Context) (*types.GenesisState, error) GetSupply(ctx context.Context, denom string) sdk.Coin HasSupply(ctx context.Context, denom string) bool @@ -213,14 +211,11 @@ type Keeper interface { DelegateCoinsFromAccountToModule(ctx context.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error UndelegateCoinsFromModuleToAccount(ctx context.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error MintCoins(ctx context.Context, moduleName string, amt sdk.Coins) error - BurnCoins(ctx context.Context, moduleName string, amt sdk.Coins) error + BurnCoins(ctx context.Context, address []byte, amt sdk.Coins) error DelegateCoins(ctx context.Context, delegatorAddr, moduleAccAddr sdk.AccAddress, amt sdk.Coins) error UndelegateCoins(ctx context.Context, moduleAccAddr, delegatorAddr sdk.AccAddress, amt sdk.Coins) error - // GetAuthority gets the address capable of executing governance proposal messages. Usually the gov module account. - GetAuthority() string - types.QueryServer } ``` @@ -274,17 +269,18 @@ Both functions compose the provided restriction with any previously provided res `AppendSendRestriction` adds the provided restriction to be run after any previously provided send restrictions. `PrependSendRestriction` adds the restriction to be run before any previously provided send restrictions. The composition will short-circuit when an error is encountered. I.e. if the first one returns an error, the second is not run. +Send restrictions can also be cleared by using `ClearSendRestriction`. -During `SendCoins`, the send restriction is applied before coins are removed from the from address and adding them to the to address. -During `InputOutputCoins`, the send restriction is applied after the input coins are removed and once for each output before the funds are added. - -A send restriction function should make use of a custom value in the context to allow bypassing that specific restriction. +During `SendCoins`, the send restriction is applied before coins are removed from the `from_address` and adding them to the `to_address`. +During `InputOutputCoins`, the send restriction is applied before the input coins are removed, once for each output before the funds are added. Send Restrictions are not placed on `ModuleToAccount` or `ModuleToModule` transfers. This is done due to modules needing to move funds to user accounts and other module accounts. This is a design decision to allow for more flexibility in the state machine. The state machine should be able to move funds between module accounts and user accounts without restrictions. Secondly this limitation would limit the usage of the state machine even for itself. users would not be able to receive rewards, not be able to move funds between module accounts. In the case that a user sends funds from a user account to the community pool and then a governance proposal is used to get those tokens into the users account this would fall under the discretion of the app chain developer to what they would like to do here. We can not make strong assumptions here. -Thirdly, this issue could lead into a chain halt if a token is disabled and the token is moved in the begin/endblock. This is the last reason we see the current change and more damaging then beneficial for users. +Thirdly, this issue could lead into a chain halt if a token is disabled and the token is moved in the begin/endblock. This is the last reason we see the current change as they are more damaging then beneficial for users. + +A send restriction function should make use of a custom value in the context to allow bypassing that specific restriction. For example, in your module's keeper package, you'd define the send restriction function: ```golang @@ -337,7 +333,8 @@ func HasBypass(ctx context.Context) bool { } ``` -Now, anywhere where you want to use `SendCoins` or `InputOutputCoins`, but you don't want your send restriction applied: +Now, anywhere where you want to use `SendCoins` or `InputOutputCoins` but you don't want your send restriction applied +you just need to apply custom value in the context: ```golang func (k Keeper) DoThing(ctx context.Context, fromAddr, toAddr sdk.AccAddress, amt sdk.Coins) error { @@ -375,35 +372,35 @@ type ViewKeeper interface { Send coins from one address to another. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L38-L53 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/tx.proto#L44-L59 ``` The message will fail under the following conditions: * The coins do not have sending enabled -* The `to` address is restricted +* The `to_address` is restricted ### MsgMultiSend -Send coins from one sender and to a series of different address. If any of the receiving addresses do not correspond to an existing account, a new account is created. +Send coins from one sender and to a series of different address. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L58-L69 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/tx.proto#L65-L75 ``` The message will fail under the following conditions: * Any of the coins do not have sending enabled -* Any of the `to` addresses are restricted +* Any of the `to_address` are restricted * Any of the coins are locked -* The inputs and outputs do not correctly correspond to one another +* The inputs and outputs do not correctly correspond to one another (eg: total_in not equal to total_out) ### MsgUpdateParams The `bank` module params can be updated through `MsgUpdateParams`, which can be done using governance proposal. The signer will always be the `gov` module account address. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L74-L88 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/tx.proto#L81-L93 ``` The message handling can fail if: @@ -412,30 +409,30 @@ The message handling can fail if: ### MsgSetSendEnabled -Used with the x/gov module to set create/edit SendEnabled entries. +Used with the x/gov module to create or edit SendEnabled entries. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/bank/v1beta1/tx.proto#L96-L117 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/tx.proto#L106-L122 ``` The message will fail under the following conditions: -* The authority is not a decodable address. -* The authority is not x/gov module's address. -* There are multiple SendEnabled entries with the same Denom. -* One or more SendEnabled entries has an invalid Denom. +* The authority is not a decodable address +* The authority is not x/gov module's address +* There are multiple SendEnabled entries with the same Denom +* One or more SendEnabled entries has an invalid Denom ### MsgBurn Used to burn coins from an account. The coins are removed from the account and the total supply is reduced. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/1af000b3ef6296f9928caf494fe5bb812990f22d/proto/cosmos/bank/v1beta1/tx.proto#L131-L148 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/proto/cosmos/bank/v1beta1/tx.proto#L130-L139 ``` This message will fail under the following conditions: -* The signer is not present +* The `from_address` is not a decodable address * The coins are not spendable * The coins are not positive * The coins are not valid @@ -451,20 +448,20 @@ The bank module emits the following events: | Type | Attribute Key | Attribute Value | | -------- | ------------- | ------------------ | | transfer | recipient | {recipientAddress} | +| transfer | sender | {senderAddress} | | transfer | amount | {amount} | | message | module | bank | | message | action | send | -| message | sender | {senderAddress} | #### MsgMultiSend | Type | Attribute Key | Attribute Value | | -------- | ------------- | ------------------ | | transfer | recipient | {recipientAddress} | +| transfer | sender | {senderAddress} | | transfer | amount | {amount} | | message | module | bank | | message | action | multisend | -| message | sender | {senderAddress} | ### Keeper Events @@ -592,9 +589,7 @@ The bank module contains the following parameters ### SendEnabled -The SendEnabled parameter is now deprecated and not to be use. It is replaced -with state store records. - +SendEnabled is depreacted and only kept for backward compatibility. For genesis, use the newly added send_enabled field in the genesis object. Storage, lookup, and manipulation of this information is now in the keeper. ### DefaultSendEnabled @@ -616,6 +611,20 @@ The `query` commands allow users to query `bank` state. simd query bank --help ``` +##### balance + +The `balance` command allows users to query account balance by specific denom. + +```shell +simd query bank balance [address] [denom] [flags] +``` + +Example: + +```shell +simd query bank balance cosmos1.. stake +``` + ##### balances The `balances` command allows users to query account balances by address. @@ -630,49 +639,65 @@ Example: simd query bank balances cosmos1.. ``` -Example Output: +##### spendable balances + +The `spendable-balances` command allows users to query account spendable balances by address. + +```shell +simd query spendable-balances [address] [flags] +``` + +Example: + +```shell +simd query bank spendable-balances cosmos1.. +``` + +##### spendable balance by denom + +The `spendable-balance` command allows users to query account spendable balance by address for a specific denom. + +```shell +simd query spendable-balance [address] [denom] [flags] +``` + +Example: -```yml -balances: -- amount: "1000000000" - denom: stake -pagination: - next_key: null - total: "0" +```shell +simd query bank spendable-balance cosmos1.. stake ``` ##### denom-metadata -The `denom-metadata` command allows users to query metadata for coin denominations. A user can query metadata for a single denomination using the `--denom` flag or all denominations without it. +The `denom-metadata` command allows users to query metadata for coin denominations. ```shell -simd query bank denom-metadata [flags] +simd query bank denom-metadata [denom] ``` Example: ```shell -simd query bank denom-metadata --denom stake +simd query bank denom-metadata stake +``` + +##### denoms-metadata + +The `denoms-metadata` command allows users to query metadata for all coin denominations. + +```shell +simd query bank denoms-metadata [flags] ``` -Example Output: +Example: -```yml -metadata: - base: stake - denom_units: - - aliases: - - STAKE - denom: stake - description: native staking token of simulation app - display: stake - name: SimApp Token - symbol: STK +```shell +simd query bank denoms-metadata ``` -##### total +##### total supply -The `total` command allows users to query the total supply of coins. A user can query the total supply for a single coin using the `--denom` flag or all coins without it. +The `total-supply` (or `total` for short) command allows users to query the total supply of coins. ```shell simd query bank total [flags] @@ -684,11 +709,18 @@ Example: simd query bank total --denom stake ``` -Example Output: +##### total supply of + +The `total-supply-of` command allows users to query the total supply for a specific coin denominations. + +```shell +simd query bank total-supply-of [denom] +``` + +Example: -```yml -amount: "10000000000" -denom: stake +```shell +simd query bank total-supply-of stake ``` ##### send-enabled @@ -705,16 +737,26 @@ Example: simd query bank send-enabled ``` -Example output: +##### params -```yml -send_enabled: -- denom: foocoin - enabled: true -- denom: barcoin -pagination: - next-key: null - total: 2 +The `params` command allows users to query for the current bank parameters. + +```shell +simd query bank params [flags] +``` + +##### denom owners + +The `denom-owners` command allows users to query for all account addresses that own a particular token denomination. + +```shell +simd query bank denom-owners [denom] [flags] +``` + +Example: + +```shell +simd query bank denom-owners stake ``` #### Transactions @@ -760,17 +802,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/Balance ``` -Example Output: - -```json -{ - "balance": { - "denom": "stake", - "amount": "1000000000" - } -} -``` - ### AllBalances The `AllBalances` endpoint allows users to query account balance by address for all denominations. @@ -788,22 +819,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/AllBalances ``` -Example Output: - -```json -{ - "balances": [ - { - "denom": "stake", - "amount": "1000000000" - } - ], - "pagination": { - "total": "1" - } -} -``` - ### DenomMetadata The `DenomMetadata` endpoint allows users to query metadata for a single coin denomination. @@ -821,28 +836,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/DenomMetadata ``` -Example Output: - -```json -{ - "metadata": { - "description": "native staking token of simulation app", - "denomUnits": [ - { - "denom": "stake", - "aliases": [ - "STAKE" - ] - } - ], - "base": "stake", - "display": "stake", - "name": "SimApp Token", - "symbol": "STK" - } -} -``` - ### DenomsMetadata The `DenomsMetadata` endpoint allows users to query metadata for all coin denominations. @@ -859,33 +852,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/DenomsMetadata ``` -Example Output: - -```json -{ - "metadatas": [ - { - "description": "native staking token of simulation app", - "denomUnits": [ - { - "denom": "stake", - "aliases": [ - "STAKE" - ] - } - ], - "base": "stake", - "display": "stake", - "name": "SimApp Token", - "symbol": "STK" - } - ], - "pagination": { - "total": "1" - } -} -``` - ### DenomOwners The `DenomOwners` endpoint allows users to query metadata for a single coin denomination. @@ -903,32 +869,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/DenomOwners ``` -Example Output: - -```json -{ - "denomOwners": [ - { - "address": "cosmos1..", - "balance": { - "denom": "stake", - "amount": "5000000000" - } - }, - { - "address": "cosmos1..", - "balance": { - "denom": "stake", - "amount": "5000000000" - } - }, - ], - "pagination": { - "total": "2" - } -} -``` - ### TotalSupply The `TotalSupply` endpoint allows users to query the total supply of all coins. @@ -945,22 +885,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/TotalSupply ``` -Example Output: - -```json -{ - "supply": [ - { - "denom": "stake", - "amount": "10000000000" - } - ], - "pagination": { - "total": "1" - } -} -``` - ### SupplyOf The `SupplyOf` endpoint allows users to query the total supply of a single coin. @@ -978,17 +902,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/SupplyOf ``` -Example Output: - -```json -{ - "amount": { - "denom": "stake", - "amount": "10000000000" - } -} -``` - ### Params The `Params` endpoint allows users to query the parameters of the `bank` module. @@ -1005,16 +918,6 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/Params ``` -Example Output: - -```json -{ - "params": { - "defaultSendEnabled": true - } -} -``` - ### SendEnabled The `SendEnabled` endpoints allows users to query the SendEnabled entries of the `bank` module. @@ -1033,22 +936,3 @@ grpcurl -plaintext \ cosmos.bank.v1beta1.Query/SendEnabled ``` -Example Output: - -```json -{ - "send_enabled": [ - { - "denom": "foocoin", - "enabled": true - }, - { - "denom": "barcoin" - } - ], - "pagination": { - "next-key": null, - "total": 2 - } -} -``` diff --git a/x/bank/go.mod b/x/bank/go.mod index 2015d9ddde4f..53fd49dabcd2 100644 --- a/x/bank/go.mod +++ b/x/bank/go.mod @@ -117,7 +117,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/bank/go.sum b/x/bank/go.sum index d7ad42cc008f..7588b565a0d7 100644 --- a/x/bank/go.sum +++ b/x/bank/go.sum @@ -412,8 +412,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/bank/keeper/keeper_test.go b/x/bank/keeper/keeper_test.go index e625712f08b8..4fe765039638 100644 --- a/x/bank/keeper/keeper_test.go +++ b/x/bank/keeper/keeper_test.go @@ -790,6 +790,7 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { suite.Require().NoError(err) fromAcc := authtypes.NewBaseAccountWithAddress(fromAddr) inputAccs := []sdk.AccountI{fromAcc} + suite.authKeeper.EXPECT().GetAccount(suite.ctx, inputAccs[0].GetAddress()).Return(inputAccs[0]).AnyTimes() toAddr1 := accAddrs[1] toAddr1Str, err := suite.authKeeper.AddressCodec().BytesToString(toAddr1) suite.Require().NoError(err) @@ -878,7 +879,7 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { }, expErr: "restriction test error", expBals: expBals{ - from: sdk.NewCoins(newFooCoin(959), newBarCoin(412)), + from: sdk.NewCoins(newFooCoin(959), newBarCoin(500)), to1: sdk.NewCoins(newFooCoin(15)), to2: sdk.NewCoins(newFooCoin(26)), }, @@ -907,7 +908,7 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { }, }, expBals: expBals{ - from: sdk.NewCoins(newFooCoin(948), newBarCoin(400)), + from: sdk.NewCoins(newFooCoin(948), newBarCoin(488)), to1: sdk.NewCoins(newFooCoin(26)), to2: sdk.NewCoins(newFooCoin(26), newBarCoin(12)), }, @@ -937,8 +938,8 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { }, expErr: "second restriction error", expBals: expBals{ - from: sdk.NewCoins(newFooCoin(904), newBarCoin(400)), - to1: sdk.NewCoins(newFooCoin(38)), + from: sdk.NewCoins(newFooCoin(948), newBarCoin(488)), + to1: sdk.NewCoins(newFooCoin(26)), to2: sdk.NewCoins(newFooCoin(26), newBarCoin(12)), }, }, @@ -966,8 +967,8 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { }, }, expBals: expBals{ - from: sdk.NewCoins(newFooCoin(904), newBarCoin(365)), - to1: sdk.NewCoins(newFooCoin(38), newBarCoin(25)), + from: sdk.NewCoins(newFooCoin(948), newBarCoin(453)), + to1: sdk.NewCoins(newFooCoin(26), newBarCoin(25)), to2: sdk.NewCoins(newFooCoin(26), newBarCoin(22)), }, }, @@ -980,7 +981,6 @@ func (suite *KeeperTestSuite) TestInputOutputCoinsWithRestrictions() { actualRestrictionArgs = nil suite.bankKeeper.SetSendRestriction(tc.fn) ctx := suite.ctx - suite.mockInputOutputCoins(inputAccs, tc.outputAddrs) input := banktypes.Input{ Address: fromStrAddr, Coins: tc.inputCoins, diff --git a/x/bank/keeper/send.go b/x/bank/keeper/send.go index 063417b6ca03..929ff2e50285 100644 --- a/x/bank/keeper/send.go +++ b/x/bank/keeper/send.go @@ -148,14 +148,15 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, return err } - err = k.subUnlockedCoins(ctx, inAddress, input.Coins) - if err != nil { - return err + // ensure all coins can be sent + type toSend struct { + AddressStr string + Address []byte + Coins sdk.Coins } - - var outAddress sdk.AccAddress + sending := make([]toSend, 0) for _, out := range outputs { - outAddress, err = k.ak.AddressCodec().StringToBytes(out.Address) + outAddress, err := k.ak.AddressCodec().StringToBytes(out.Address) if err != nil { return err } @@ -165,13 +166,25 @@ func (k BaseSendKeeper) InputOutputCoins(ctx context.Context, input types.Input, return err } - if err := k.addCoins(ctx, outAddress, out.Coins); err != nil { + sending = append(sending, toSend{ + Address: outAddress, + AddressStr: out.Address, + Coins: out.Coins, + }) + } + + if err := k.subUnlockedCoins(ctx, inAddress, input.Coins); err != nil { + return err + } + + for _, out := range sending { + if err := k.addCoins(ctx, out.Address, out.Coins); err != nil { return err } if err := k.EventService.EventManager(ctx).EmitKV( types.EventTypeTransfer, - event.NewAttribute(types.AttributeKeyRecipient, out.Address), + event.NewAttribute(types.AttributeKeyRecipient, out.AddressStr), event.NewAttribute(types.AttributeKeySender, input.Address), event.NewAttribute(sdk.AttributeKeyAmount, out.Coins.String()), ); err != nil { diff --git a/x/circuit/autocli.go b/x/circuit/autocli.go index 898028247808..e9cc67701cf7 100644 --- a/x/circuit/autocli.go +++ b/x/circuit/autocli.go @@ -43,7 +43,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { "SOME_MSGS" = 1, "ALL_MSGS" = 2, "SUPER_ADMIN" = 3,`, - Example: fmt.Sprintf(`%s circuit authorize [address] '{"level":1,"limit_type_urls":["/cosmos.bank.v1beta1.MsgSend, /cosmos.bank.v1beta1.MsgMultiSend"]}'"`, version.AppName), + Example: fmt.Sprintf(`%s tx circuit authorize [address] '{"level":1,"limit_type_urls":["/cosmos.bank.v1beta1.MsgSend, /cosmos.bank.v1beta1.MsgMultiSend"]}'"`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "grantee"}, {ProtoField: "permissions"}, // TODO(@julienrbrt) Support flattening msg for setting each field as a positional arg @@ -53,7 +53,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcMethod: "TripCircuitBreaker", Use: "disable ", Short: "Disable a message from being executed", - Example: fmt.Sprintf(`%s circuit disable "/cosmos.bank.v1beta1.MsgSend /cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName), + Example: fmt.Sprintf(`%s tx circuit disable "/cosmos.bank.v1beta1.MsgSend /cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "msg_type_urls", Varargs: true}, }, @@ -62,7 +62,7 @@ func (am AppModule) AutoCLIOptions() *autocliv1.ModuleOptions { RpcMethod: "ResetCircuitBreaker", Use: "reset ", Short: "Enable a message to be executed", - Example: fmt.Sprintf(`%s circuit reset "/cosmos.bank.v1beta1.MsgSend /cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName), + Example: fmt.Sprintf(`%s tx circuit reset "/cosmos.bank.v1beta1.MsgSend /cosmos.bank.v1beta1.MsgMultiSend"`, version.AppName), PositionalArgs: []*autocliv1.PositionalArgDescriptor{ {ProtoField: "msg_type_urls", Varargs: true}, }, diff --git a/x/circuit/go.mod b/x/circuit/go.mod index e1be4f196dce..57801be443d0 100644 --- a/x/circuit/go.mod +++ b/x/circuit/go.mod @@ -121,7 +121,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/circuit/go.sum b/x/circuit/go.sum index ceb6f972a420..c9df997e10ec 100644 --- a/x/circuit/go.sum +++ b/x/circuit/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/consensus/README.md b/x/consensus/README.md index 2af97a6a32db..83add3f0bc95 100644 --- a/x/consensus/README.md +++ b/x/consensus/README.md @@ -10,33 +10,53 @@ Functionality to modify CometBFT's ABCI consensus params. ## Contents +* [Abstract](#abstract) +* [Contents](#contents) * [State](#state) * [Params](#params) -* [Keepers](#keepers) +* [Keeper](#keeper) * [Messages](#messages) -* [Consensus Messages](#consensus-messages) + * [UpdateParams](#updateparams) * [Events](#events) - * [Message Events](#message-events) - ## State -The `x/consensus` module keeps state of the consensus params from cometbft.: +The `x/consensus` module keeps state of the consensus params from CometBFT. ## Params -The consensus module stores it's params in state with the prefix of `0x05`, +The consensus module stores its params in state with the prefix of `0x05`, it can be updated with governance or the address with authority. * Params: `0x05 | ProtocolBuffer(cometbft.ConsensusParams)` ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/consensus/proto/cosmos/consensus/v1/consensus.proto#L9-L15 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/consensus/proto/cosmos/consensus/v1/query.proto#L21-L27 +``` + +```protobuf reference +https://github.com/cometbft/cometbft/blob/v0.34.35/proto/tendermint/types/params.proto#L11-L18 ``` -## Keepers +## Keeper + +The Keeper of the `x/consensus` module provides the following functions: + +* `Params`: Retrieves the current consensus parameters. + +* `UpdateParams`: Updates the consensus parameters. Only the authority can perform this operation. + +* `BlockParams`: Returns the maximum gas and bytes allowed in a block. + +* `ValidatorPubKeyTypes`: Provides the list of public key types allowed for validators. + +* `EvidenceParams`: Returns the evidence parameters, including maximum age and bytes. + +* `AppVersion`: Returns the current application version. + + +Note: It is recommended to use the `x/consensus` module keeper to get consensus params instead of accessing them through the context. -The consensus module provides methods to Set and Get consensus params. It is recommended to use the `x/consensus` module keeper to get consensus params instead of accessing them through the context. ## Messages @@ -45,7 +65,7 @@ The consensus module provides methods to Set and Get consensus params. It is rec Update consensus params. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/consensus/proto/cosmos/consensus/v1/tx.proto#L23-L44 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/consensus/proto/cosmos/consensus/v1/tx.proto#L24-L44 ``` The message will fail under the following conditions: diff --git a/x/consensus/go.mod b/x/consensus/go.mod index 09946d4fa364..cee2372dc92d 100644 --- a/x/consensus/go.mod +++ b/x/consensus/go.mod @@ -120,7 +120,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/consensus/go.sum b/x/consensus/go.sum index 073c8d594541..6a6b2df0b205 100644 --- a/x/consensus/go.sum +++ b/x/consensus/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/distribution/go.mod b/x/distribution/go.mod index 53e9b070db05..dac4ae3041e6 100644 --- a/x/distribution/go.mod +++ b/x/distribution/go.mod @@ -122,7 +122,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/distribution/go.sum b/x/distribution/go.sum index d7ad42cc008f..7588b565a0d7 100644 --- a/x/distribution/go.sum +++ b/x/distribution/go.sum @@ -412,8 +412,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/epochs/README.md b/x/epochs/README.md index dcd7eb7b5176..7b0b0b285767 100644 --- a/x/epochs/README.md +++ b/x/epochs/README.md @@ -68,22 +68,6 @@ The `epochs` module emits the following events: Epochs keeper module provides utility functions to manage epochs. -``` go -// Keeper is the interface for epochs module keeper -type Keeper interface { - // GetEpochInfo returns epoch info by identifier - GetEpochInfo(ctx sdk.Context, identifier string) types.EpochInfo - // SetEpochInfo set epoch info - SetEpochInfo(ctx sdk.Context, epoch types.EpochInfo) - // DeleteEpochInfo delete epoch info - DeleteEpochInfo(ctx sdk.Context, identifier string) - // IterateEpochInfo iterate through epochs - IterateEpochInfo(ctx sdk.Context, fn func(index int64, epochInfo types.EpochInfo) (stop bool)) - // Get all epoch infos - AllEpochInfos(ctx sdk.Context) []types.EpochInfo -} -``` - ## Hooks ```go diff --git a/x/epochs/go.mod b/x/epochs/go.mod index 73841ae08da3..b8262cba4f35 100644 --- a/x/epochs/go.mod +++ b/x/epochs/go.mod @@ -119,7 +119,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/epochs/go.sum b/x/epochs/go.sum index 073c8d594541..6a6b2df0b205 100644 --- a/x/epochs/go.sum +++ b/x/epochs/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/epochs/keeper/epoch.go b/x/epochs/keeper/epoch.go index 3943cf4c61c5..f743227ed5bd 100644 --- a/x/epochs/keeper/epoch.go +++ b/x/epochs/keeper/epoch.go @@ -7,6 +7,11 @@ import ( "cosmossdk.io/x/epochs/types" ) +// GetEpochInfo returns epoch info by identifier. +func (k Keeper) GetEpochInfo(ctx context.Context, identifier string) (types.EpochInfo, error) { + return k.EpochInfo.Get(ctx, identifier) +} + // AddEpochInfo adds a new epoch info. Will return an error if the epoch fails validation, // or re-uses an existing identifier. // This method also sets the start time if left unset, and sets the epoch start height. diff --git a/x/evidence/go.mod b/x/evidence/go.mod index 5059afdc2ba4..94af124c0a3d 100644 --- a/x/evidence/go.mod +++ b/x/evidence/go.mod @@ -123,7 +123,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/evidence/go.sum b/x/evidence/go.sum index ceb6f972a420..c9df997e10ec 100644 --- a/x/evidence/go.sum +++ b/x/evidence/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/feegrant/go.mod b/x/feegrant/go.mod index b8c5e615e1e5..56310d95579a 100644 --- a/x/feegrant/go.mod +++ b/x/feegrant/go.mod @@ -131,7 +131,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/feegrant/go.sum b/x/feegrant/go.sum index db92ca3dd2e0..8e11511b6d57 100644 --- a/x/feegrant/go.sum +++ b/x/feegrant/go.sum @@ -422,8 +422,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/genutil/client/cli/migrate.go b/x/genutil/client/cli/migrate.go index 2763ba06cfb4..2b2a1c856b74 100644 --- a/x/genutil/client/cli/migrate.go +++ b/x/genutil/client/cli/migrate.go @@ -29,7 +29,7 @@ func MigrateGenesisCmd(migrations types.MigrationMap) *cobra.Command { Use: "migrate ", Short: "Migrate genesis to a specified target version", Long: "Migrate the source genesis into the target version and print to STDOUT", - Example: fmt.Sprintf("%s migrate v0.47 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2019-04-22T17:00:00Z", version.AppName), + Example: fmt.Sprintf("%s genesis migrate v0.47 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2019-04-22T17:00:00Z", version.AppName), Args: cobra.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { return MigrateHandler(cmd, args, migrations) diff --git a/x/gov/README.md b/x/gov/README.md index 15f86d335b1e..cda1af118b6c 100644 --- a/x/gov/README.md +++ b/x/gov/README.md @@ -18,13 +18,9 @@ currently supports: * **Proposal submission:** Users can submit proposals with a deposit. Once the minimum deposit is reached, the proposal enters voting period. The minimum deposit can be reached by collecting deposits from different users (including proposer) within deposit period. * **Vote:** Participants can vote on proposals that reached MinDeposit and entered voting period. -* **Inheritance and penalties:** Delegators inherit their validator's vote if -they don't vote themselves. +* **Inheritance and penalties:** Delegators, by default, inherit their validator's vote if they don't vote themselves. * **Claiming deposit:** Users that deposited on proposals can recover their -deposits if the proposal was accepted or rejected. If the proposal was vetoed, or never entered voting period (minimum deposit not reached within deposit period), the deposit is burned. - -This module is in use on the Cosmos Hub (a.k.a [gaia](https://github.com/cosmos/gaia)). - +deposits if the proposal was accepted or rejected. If the proposal was vetoed, or never entered voting period (minimum deposit not reached within deposit period), the deposit is burned (or refunded depending on the gov parameters). ## Contents @@ -59,7 +55,6 @@ staking token of the chain. * [Metadata](#metadata) * [Proposal](#proposal-3) * [Vote](#vote-5) -* [Future Improvements](#future-improvements) ## Concepts @@ -87,7 +82,7 @@ proposal passes. The messages are executed by the governance `ModuleAccount` its such as `x/upgrade`, that want to allow certain messages to be executed by governance only should add a whitelist within the respective msg server, granting the governance module the right to execute the message once a quorum has been reached. The governance -module uses the `MsgServiceRouter` to check that these messages are correctly constructed +module uses the core `router.Service` to check that these messages are correctly constructed and have a respective path to execute on but do not perform a full validity check. :::warning @@ -118,16 +113,22 @@ proposal is finalized (passed or rejected). #### Deposit refund and burn When a proposal is finalized, the coins from the deposit are either refunded or burned -according to the final tally of the proposal: +according to the final tally of the proposal and the governance module parameters: +* All refunded or burned deposits are removed from the state. Events are issued when + burning or refunding a deposit. * If the proposal is approved or rejected but *not* vetoed, each deposit will be automatically refunded to its respective depositor (transferred from the governance `ModuleAccount`). -* When the proposal is vetoed with greater than 1/3, deposits will be burned from the - governance `ModuleAccount` and the proposal information along with its deposit - information will be removed from state. -* All refunded or burned deposits are removed from the state. Events are issued when - burning or refunding a deposit. +* If the proposal is marked as Spam, the deposit will be burned. + +For other cases, they are three parameters that define if the deposit of a proposal should be burned or returned to the depositors. + +* `BurnVoteVeto` burns the proposal deposit if the proposal gets vetoed. +* `BurnVoteQuorum` burns the proposal deposit if the vote does not reach quorum. +* `BurnProposalDepositPrevote` burns the proposal deposit if it does not enter the voting phase. + +> Note: These parameters are modifiable via governance. ### Vote @@ -144,7 +145,7 @@ Note that when *participants* have bonded and unbonded Atoms, their voting power Once a proposal reaches `MinDeposit`, it immediately enters `Voting period`. We define `Voting period` as the interval between the moment the vote opens and -the moment the vote closes. The initial value of `Voting period` is 2 weeks. +the moment the vote closes. The default value of `Voting period` is 2 weeks but is modifiable at genesis or governance. #### Option set @@ -163,8 +164,6 @@ The initial option set includes the following options: allows voters to signal that they do not intend to vote in favor or against the proposal but accept the result of the vote. -*Note: from the UI, for urgent proposals we should maybe add a ‘Not Urgent’ option that casts a `NoWithVeto` vote.* - #### Weighted Votes [ADR-037](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-037-gov-split-vote.md) introduces the weighted vote feature which allows a staker to split their votes into several voting options. For example, it could use 70% of its voting power to vote Yes and 30% of its voting power to vote No. @@ -174,11 +173,11 @@ Often times the entity owning that address might not be a single individual. For To represent weighted vote on chain, we use the following Protobuf message. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1beta1/gov.proto#L34-L47 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/gov.proto#L56-L63 ``` ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1beta1/gov.proto#L181-L201 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/gov.proto#L202-L219 ``` For a weighted vote to be valid, the `options` field must not contain duplicate vote options, and the sum of weights of all options must be equal to 1. @@ -204,7 +203,7 @@ By default, `YesQuorum` is set to 0, which means no minimum. ### Proposal Types -Proposal types have been introduced in ADR-069. +Proposal types have been introduced in [ADR-069](https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-069-gov-improvements.md). #### Standard proposal @@ -225,17 +224,16 @@ A chain can optionally set a list of authorized addresses that can submit optimi #### Multiple Choice Proposals A multiple choice proposal is a proposal where the voting options can be defined by the proposer. -The number of voting options is limited to a maximum of 4. +The number of voting options is limited to a maximum of **4**. Multiple choice proposals, contrary to any other proposal type, cannot have messages to execute. They are only text proposals. -#### Threshold +### Threshold -Threshold is defined as the minimum proportion of `Yes` votes (excluding -`Abstain` votes) for the proposal to be accepted. +Threshold is defined as the minimum proportion of `Yes` votes (excluding `Abstain` votes) for the proposal to be accepted. -Initially, the threshold is set at 50% of `Yes` votes, excluding `Abstain` -votes. A possibility to veto exists if more than 1/3rd of all votes are -`NoWithVeto` votes. Note, both of these values are derived from the `TallyParams` +Initially, the threshold is set at 50% of `Yes` votes, excluding `Abstain` votes. +A possibility to veto exists if more than 1/3rd of all votes are `NoWithVeto` votes. +Note, both of these values are derived from the `Params` on-chain parameter, which is modifiable by governance. This means that proposals are accepted iff: @@ -249,43 +247,37 @@ This means that proposals are accepted iff: For expedited proposals, by default, the threshold is higher than with a *normal proposal*, namely, 66.7%. -#### Inheritance +### Inheritance -If a delegator does not vote, it will inherit its validator vote. +If a delegator does not vote, by default, it will inherit its validator vote. -* If the delegator votes before its validator, it will not inherit from the - validator's vote. -* If the delegator votes after its validator, it will override its validator - vote with its own. If the proposal is urgent, it is possible - that the vote will close before delegators have a chance to react and +* If the delegator votes before its validator, it will not inherit from the validator's vote. +* If the delegator votes after its validator, it will override its validator vote with its own. + If the proposal is urgent, it is possible that the vote will close before delegators have a chance to react and override their validator's vote. This is not a problem, as proposals require more than 2/3rd of the total voting power to pass, when tallied at the end of the voting period. Because as little as 1/3 + 1 validation power could collude to censor transactions, non-collusion is already assumed for ranges exceeding this threshold. -#### Validator’s punishment for non-voting - -At present, validators are not punished for failing to vote. - -#### Governance address - -Later, we may add permissioned keys that could only sign txs from certain modules. For the MVP, the `Governance address` will be the main validator address generated at account creation. This address corresponds to a different PrivKey than the CometBFT PrivKey which is responsible for signing consensus messages. Validators thus do not have to sign governance transactions with the sensitive CometBFT PrivKey. - -#### Burnable Params +This behavior can be changed by passing a custom tally calculation function to the governance module. -There are three parameters that define if the deposit of a proposal should be burned or returned to the depositors. +```go reference +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/keeper/config.go#L33-L35 +``` -* `BurnVoteVeto` burns the proposal deposit if the proposal gets vetoed. -* `BurnVoteQuorum` burns the proposal deposit if the vote does not reach quorum. -* `BurnProposalDepositPrevote` burns the proposal deposit if it does not enter the voting phase. +#### Validator’s punishment for non-voting -> Note: These parameters are modifiable via governance. +At present, validators are not punished for failing to vote. #### Execution -Execution is the process of executing the messages contained in a proposal. The execution phase will commence after the proposal has been accepted by the network. The messages contained in the proposal will be executed in the order they were submitted. +Execution is the process of executing the messages contained in a proposal. The execution phase will commence after the proposal has been accepted by the network. The messages contained in the proposal will be executed in the order they were submitted. All messages must be executed successfully for the proposal to be considered successful. I + +If a proposal passes but fails to execute, the proposal will be marked as `StatusFailed`. This status is different from `StatusRejected`, which is used when a proposal fails to pass. Execution has an upper limit on how much gas can be consumed in a single block. This limit is defined by the `ProposalExecutionGas` parameter. ## State +The governance module uses [collections](https://docs.cosmos.network/v0.50/build/packages/collections) for state management. + ### Constitution `Constitution` is found in the genesis state. It is a string field intended to be used to describe the purpose of a particular blockchain, and its expected norms. A few examples of how the constitution field can be used: @@ -328,7 +320,7 @@ unique id and contains a series of timestamps: `submit_time`, `deposit_end_time` `voting_start_time`, `voting_end_time` which track the lifecycle of a proposal ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L51-L99 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/gov.proto#L78-L134 ``` A proposal will generally require more than just a set of messages to explain its @@ -354,7 +346,13 @@ the following `JSON` template: This makes it far easier for clients to support multiple networks. Fields metadata, title and summary have a maximum length that is chosen by the app developer, and -passed into the gov keeper as a config. The default maximum length are: for the title 255 characters, for the metadata 255 characters and for summary 10200 characters (40 times the one of the title). +passed into the gov keeper as a config (`x/gov/keeper/config`). + +The default maximum length are: + +```go reference +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/keeper/config.go#L38-L47 +``` #### Writing a module that uses governance @@ -372,37 +370,20 @@ Note, any message can be executed by governance if embedded in `MsgSudoExec`. ### Parameters and base types -`Parameters` define the rules according to which votes are run. There can only -be one active parameter set at any given time. If governance wants to change a -parameter set, either to modify a value or add/remove a parameter field, a new -parameter set has to be created and the previous one rendered inactive. - -#### DepositParams - -```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L152-L162 -``` - -#### VotingParams - -```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L164-L168 -``` - -#### TallyParams +`Params` define the rules according to which votes are run. If governance wants to change a +parameter it can do so by submitting a gov `MsgUpdateParams` governance proposal. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L170-L182 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/gov.proto#L259-L348 ``` -Parameters are stored in a global `GlobalParams` KVStore. +Parameters are stored in the `gov` store under the key `ParamsKey`. Additionally, we introduce some basic types: ```go type ProposalStatus byte - const ( StatusNil ProposalStatus = 0x00 StatusDepositPeriod ProposalStatus = 0x01 // Proposal is submitted. Participants can deposit on it but not vote @@ -416,7 +397,7 @@ const ( ### Deposit ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/gov.proto#L38-L49 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/gov.proto#L65-L76 ``` ### ValidatorGovInfo @@ -430,50 +411,12 @@ This type is used in a temp map when tallying } ``` -## Stores - -:::note -Stores are KVStores in the multi-store. The key to find the store is the first parameter in the list -::: - -We will use one KVStore `Governance` to store four mappings: - -* A mapping from `proposalID|'proposal'` to `Proposal`. -* A mapping from `proposalID|'addresses'|address` to `Vote`. This mapping allows - us to query all addresses that voted on the proposal along with their vote by - doing a range query on `proposalID:addresses`. -* A mapping from `ParamsKey|'Params'` to `Params`. This map allows to query all - x/gov params. - -For pseudocode purposes, here are the two functions we will use to read or write in stores: - -* `load(StoreKey, Key)`: Retrieve item stored at key `Key` in store found at key `StoreKey` in the multistore -* `store(StoreKey, Key, value)`: Write value `Value` at key `Key` in store found at key `StoreKey` in the multistore - -### Proposal Processing Queue - -**Store:** - -* `ProposalProcessingQueue`: A queue `queue[proposalID]` containing all the - `ProposalIDs` of proposals that reached `MinDeposit`. During each `EndBlock`, - all the proposals that have reached the end of their voting period are processed. - To process a finished proposal, the application tallies the votes, computes the - votes of each validator and checks if every validator in the validator set has - voted. If the proposal is accepted, deposits are refunded. Finally, the proposal - content `Handler` is executed. - ### Legacy Proposal :::warning -Legacy proposals are deprecated. Use the new proposal flow by granting the governance module the right to execute the message. +Legacy proposals (`gov/v1beta1`) are deprecated. Use the new proposal flow by granting the governance module the right to execute the message. ::: -A legacy proposal is the old implementation of governance proposal. -Contrary to proposal that can contain any messages, a legacy proposal allows to submit a set of pre-defined proposals. -These proposals are defined by their types and handled by handlers that are registered in the gov v1beta1 router. - -More information on how to submit proposals is in the [client section](#client). - ## Messages ### Proposal Submission @@ -481,37 +424,28 @@ More information on how to submit proposals is in the [client section](#client). Proposals can be submitted by any account via a `MsgSubmitProposal` or a `MsgSubmitMultipleChoiceProposal` transaction. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/tx.proto#L42-L69 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/tx.proto#L64-L102 ``` -:::note +```protobuf reference +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/tx.proto#L229-L256 +``` + +:::tip A multiple choice proposal is a proposal where the voting options can be defined by the proposer. It cannot have messages to execute. It is only a text proposal. -::: - -:::warning -Submitting a multiple choice proposal using `MsgSubmitProposal` is invalid, as vote options cannot be defined. +This means submitting a multiple choice proposal using `MsgSubmitProposal` is invalid, as vote options cannot be defined. ::: All `sdk.Msgs` passed into the `messages` field of a `MsgSubmitProposal` message -must be registered in the app's `MsgServiceRouter`. Each of these messages must +must be registered in the app's message router. Each of these messages must have one signer, namely the gov module account. And finally, the metadata length must not be larger than the `maxMetadataLen` config passed into the gov keeper. The `initialDeposit` must be strictly positive and conform to the accepted denom of the `MinDeposit` param. -**State modifications:** - -* Generate new `proposalID` -* Create new `Proposal` -* Initialise `Proposal`'s attributes -* Decrease balance of sender by `InitialDeposit` -* If `MinDeposit` is reached: - * Push `proposalID` in `ProposalProcessingQueue` -* Transfer `InitialDeposit` from the `Proposer` to the governance `ModuleAccount` - ### Deposit -Once a proposal is submitted, if `Proposal.TotalDeposit < ActiveParam.MinDeposit`, Atom holders can send +Once a proposal is submitted, if `Proposal.TotalDeposit < GovParams.MinDeposit`, Atom holders can send `MsgDeposit` transactions to increase the proposal's deposit. A deposit is accepted iff: @@ -521,36 +455,19 @@ A deposit is accepted iff: * The deposited coins are conform to the accepted denom from the `MinDeposit` param ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/tx.proto#L134-L147 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/tx.proto#L167-L180 ``` -**State modifications:** - -* Decrease balance of sender by `deposit` -* Add `deposit` of sender in `proposal.Deposits` -* Increase `proposal.TotalDeposit` by sender's `deposit` -* If `MinDeposit` is reached: - * Push `proposalID` in `ProposalProcessingQueueEnd` -* Transfer `Deposit` from the `proposer` to the governance `ModuleAccount` - ### Vote -Once `ActiveParam.MinDeposit` is reached, voting period starts. From there, +Once `GovParams.MinDeposit` is reached, voting period starts. From there, bonded Atom holders are able to send `MsgVote` transactions to cast their vote on the proposal. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/gov/v1/tx.proto#L92-L108 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/gov/proto/cosmos/gov/v1/tx.proto#L125-L141 ``` -**State modifications:** - -* Record `Vote` of sender - -:::note -Gas cost for this message has to take into account the future tallying of the vote in EndBlocker. -::: - ## Events The governance module emits the following events: @@ -659,9 +576,44 @@ In addition to the parameters above, the governance module can also be configure If configured, these params will take precedence over the global params for a specific proposal. :::warning -Currently, messaged based parameters limit the number of messages that can be included in a proposal to 1 if a messaged based parameter is configured. +Currently, messaged based parameters limit the number of messages that can be included in a proposal. +Only messages that have the same message parameters can be included in the same proposal. +::: + +## Metadata + +The gov module has two locations for metadata where users can provide further context about the on-chain actions they are taking. By default all metadata fields have a 255 character length field where metadata can be stored in json format, either on-chain or off-chain depending on the amount of data required. Here we provide a recommendation for the json structure and where the data should be stored. There are two important factors in making these recommendations. First, that the gov and group modules are consistent with one another, note the number of proposals made by all groups may be quite large. Second, that client applications such as block explorers and governance interfaces have confidence in the consistency of metadata structure across chains. + +### Proposal + +Location: off-chain as json object stored on IPFS (mirrors [group proposal](../group/README.md#metadata)) + +```json +{ + "title": "", + "authors": [""], + "summary": "", + "details": "", + "proposal_forum_url": "", + "vote_option_context": "", +} +``` + +:::note +The `authors` field is an array of strings, this is to allow for multiple authors to be listed in the metadata. +In v0.46, the `authors` field is a comma-separated string. Frontends are encouraged to support both formats for backwards compatibility. ::: +### Vote + +Location: on-chain as json within 255 character limit (mirrors [group vote](../group/README.md#metadata)) + +```json +{ + "justification": "", +} +``` + ## Client ### CLI @@ -1043,41 +995,6 @@ By default the metadata, summary and title are both limited by 255 characters, t When metadata is not specified, the title is limited to 255 characters and the summary 40x the title length. ::: -##### submit-legacy-proposal - -The `submit-legacy-proposal` command allows users to submit a governance legacy proposal along with an initial deposit. - -```bash -simd tx gov submit-legacy-proposal [command] [flags] -``` - -Example: - -```bash -simd tx gov submit-legacy-proposal --title="Test Proposal" --description="testing" --type="Text" --deposit="100000000stake" --from cosmos1.. -``` - -Example (`param-change`): - -```bash -simd tx gov submit-legacy-proposal param-change proposal.json --from cosmos1.. -``` - -```json -{ - "title": "Test Proposal", - "description": "testing, testing, 1, 2, 3", - "changes": [ - { - "subspace": "staking", - "key": "MaxValidators", - "value": 100 - } - ], - "deposit": "10000000stake" -} -``` - ##### cancel-proposal Once proposal is canceled, from the deposits of proposal `deposits * proposal_cancel_ratio` will be burned or sent to `ProposalCancelDest` address , if `ProposalCancelDest` is empty then deposits will be burned. The `remaining deposits` will be sent to depositors. @@ -1128,10 +1045,8 @@ A user can query the `gov` module using gRPC endpoints. The `Proposal` endpoint allows users to query a given proposal. -Using legacy v1beta1: - ```bash -cosmos.gov.v1beta1.Query/Proposal +cosmos.gov.v1.Query/Proposal ``` Example: @@ -1140,312 +1055,99 @@ Example: grpcurl -plaintext \ -d '{"proposal_id":"1"}' \ localhost:9090 \ - cosmos.gov.v1beta1.Query/Proposal + cosmos.gov.v1.Query/Proposal ``` -Example Output: - -```bash -{ - "proposal": { - "proposalId": "1", - "content": {"@type":"/cosmos.gov.v1beta1.TextProposal","description":"testing, testing, 1, 2, 3","title":"Test Proposal"}, - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "finalTallyResult": { - "yes": "0", - "abstain": "0", - "no": "0", - "noWithVeto": "0" - }, - "submitTime": "2021-09-16T19:40:08.712440474Z", - "depositEndTime": "2021-09-18T19:40:08.712440474Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10000000" - } - ], - "votingStartTime": "2021-09-16T19:40:08.712440474Z", - "votingEndTime": "2021-09-18T19:40:08.712440474Z", - "title": "Test Proposal", - "summary": "testing, testing, 1, 2, 3" - } -} -``` +#### Proposals -Using v1: +The `Proposals` endpoint allows users to query all proposals with optional filters. ```bash -cosmos.gov.v1.Query/Proposal +cosmos.gov.v1.Query/Proposals ``` Example: ```bash grpcurl -plaintext \ - -d '{"proposal_id":"1"}' \ localhost:9090 \ - cosmos.gov.v1.Query/Proposal -``` - -Example Output: - -```bash -{ - "proposal": { - "id": "1", - "messages": [ - {"@type":"/cosmos.bank.v1beta1.MsgSend","amount":[{"denom":"stake","amount":"10"}],"fromAddress":"cosmos1..","toAddress":"cosmos1.."} - ], - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "finalTallyResult": { - "yesCount": "0", - "abstainCount": "0", - "noCount": "0", - "noWithVetoCount": "0" - }, - "submitTime": "2022-03-28T11:50:20.819676256Z", - "depositEndTime": "2022-03-30T11:50:20.819676256Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10000000" - } - ], - "votingStartTime": "2022-03-28T14:25:26.644857113Z", - "votingEndTime": "2022-03-30T14:25:26.644857113Z", - "metadata": "AQ==", - "title": "Test Proposal", - "summary": "testing, testing, 1, 2, 3" - } -} + cosmos.gov.v1.Query/Proposals ``` -#### Proposals - -The `Proposals` endpoint allows users to query all proposals with optional filters. +#### Vote -Using legacy v1beta1: +The `Vote` endpoint allows users to query a vote for a given proposal. ```bash -cosmos.gov.v1beta1.Query/Proposals +cosmos.gov.v1.Query/Vote ``` Example: ```bash grpcurl -plaintext \ + -d '{"proposal_id":"1","voter":"cosmos1.."}' \ localhost:9090 \ - cosmos.gov.v1beta1.Query/Proposals + cosmos.gov.v1.Query/Vote ``` -Example Output: - -```bash -{ - "proposals": [ - { - "proposalId": "1", - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "finalTallyResult": { - "yes": "0", - "abstain": "0", - "no": "0", - "noWithVeto": "0" - }, - "submitTime": "2022-03-28T11:50:20.819676256Z", - "depositEndTime": "2022-03-30T11:50:20.819676256Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10000000010" - } - ], - "votingStartTime": "2022-03-28T14:25:26.644857113Z", - "votingEndTime": "2022-03-30T14:25:26.644857113Z" - }, - { - "proposalId": "2", - "status": "PROPOSAL_STATUS_DEPOSIT_PERIOD", - "finalTallyResult": { - "yes": "0", - "abstain": "0", - "no": "0", - "noWithVeto": "0" - }, - "submitTime": "2022-03-28T14:02:41.165025015Z", - "depositEndTime": "2022-03-30T14:02:41.165025015Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10" - } - ], - "votingStartTime": "0001-01-01T00:00:00Z", - "votingEndTime": "0001-01-01T00:00:00Z" - } - ], - "pagination": { - "total": "2" - } -} - -``` +#### Votes -Using v1: +The `Votes` endpoint allows users to query all votes for a given proposal. ```bash -cosmos.gov.v1.Query/Proposals +cosmos.gov.v1.Query/Votes ``` Example: ```bash grpcurl -plaintext \ + -d '{"proposal_id":"1"}' \ localhost:9090 \ - cosmos.gov.v1.Query/Proposals -``` - -Example Output: - -```bash -{ - "proposals": [ - { - "id": "1", - "messages": [ - {"@type":"/cosmos.bank.v1beta1.MsgSend","amount":[{"denom":"stake","amount":"10"}],"fromAddress":"cosmos1..","toAddress":"cosmos1.."} - ], - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "finalTallyResult": { - "yesCount": "0", - "abstainCount": "0", - "noCount": "0", - "noWithVetoCount": "0" - }, - "submitTime": "2022-03-28T11:50:20.819676256Z", - "depositEndTime": "2022-03-30T11:50:20.819676256Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10000000010" - } - ], - "votingStartTime": "2022-03-28T14:25:26.644857113Z", - "votingEndTime": "2022-03-30T14:25:26.644857113Z", - "metadata": "AQ==", - "title": "Proposal Title", - "summary": "Proposal Summary" - }, - { - "id": "2", - "messages": [ - {"@type":"/cosmos.bank.v1beta1.MsgSend","amount":[{"denom":"stake","amount":"10"}],"fromAddress":"cosmos1..","toAddress":"cosmos1.."} - ], - "status": "PROPOSAL_STATUS_DEPOSIT_PERIOD", - "finalTallyResult": { - "yesCount": "0", - "abstainCount": "0", - "noCount": "0", - "noWithVetoCount": "0" - }, - "submitTime": "2022-03-28T14:02:41.165025015Z", - "depositEndTime": "2022-03-30T14:02:41.165025015Z", - "totalDeposit": [ - { - "denom": "stake", - "amount": "10" - } - ], - "metadata": "AQ==", - "title": "Proposal Title", - "summary": "Proposal Summary" - } - ], - "pagination": { - "total": "2" - } -} + cosmos.gov.v1.Query/Votes ``` -#### Vote - -The `Vote` endpoint allows users to query a vote for a given proposal. +#### Params -Using legacy v1beta1: +The `Params` endpoint allows users to query all parameters for the `gov` module. ```bash -cosmos.gov.v1beta1.Query/Vote +cosmos.gov.v1.Query/Params ``` Example: ```bash grpcurl -plaintext \ - -d '{"proposal_id":"1","voter":"cosmos1.."}' \ + -d '{"params_type":"voting"}' \ localhost:9090 \ - cosmos.gov.v1beta1.Query/Vote + cosmos.gov.v1.Query/Params ``` -Example Output: - -```bash -{ - "vote": { - "proposalId": "1", - "voter": "cosmos1..", - "option": "VOTE_OPTION_YES", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1000000000000000000" - } - ] - } -} -``` +#### Deposit -Using v1: +The `Deposit` endpoint allows users to query a deposit for a given proposal from a given depositor. ```bash -cosmos.gov.v1.Query/Vote +cosmos.gov.v1.Query/Deposit ``` Example: ```bash grpcurl -plaintext \ - -d '{"proposal_id":"1","voter":"cosmos1.."}' \ + '{"proposal_id":"1","depositor":"cosmos1.."}' \ localhost:9090 \ - cosmos.gov.v1.Query/Vote -``` - -Example Output: - -```bash -{ - "vote": { - "proposalId": "1", - "voter": "cosmos1..", - "option": "VOTE_OPTION_YES", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ] - } -} + cosmos.gov.v1.Query/Deposit ``` -#### Votes - -The `Votes` endpoint allows users to query all votes for a given proposal. +#### deposits -Using legacy v1beta1: +The `Deposits` endpoint allows users to query all deposits for a given proposal. ```bash -cosmos.gov.v1beta1.Query/Votes +cosmos.gov.v1.Query/Deposits ``` Example: @@ -1454,35 +1156,15 @@ Example: grpcurl -plaintext \ -d '{"proposal_id":"1"}' \ localhost:9090 \ - cosmos.gov.v1beta1.Query/Votes + cosmos.gov.v1.Query/Deposits ``` -Example Output: - -```bash -{ - "votes": [ - { - "proposalId": "1", - "voter": "cosmos1..", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1000000000000000000" - } - ] - } - ], - "pagination": { - "total": "1" - } -} -``` +#### TallyResult -Using v1: +The `TallyResult` endpoint allows users to query the tally of a given proposal. ```bash -cosmos.gov.v1.Query/Votes +cosmos.gov.v1.Query/TallyResult ``` Example: @@ -1491,353 +1173,16 @@ Example: grpcurl -plaintext \ -d '{"proposal_id":"1"}' \ localhost:9090 \ - cosmos.gov.v1.Query/Votes + cosmos.gov.v1.Query/TallyResult ``` -Example Output: - -```bash -{ - "votes": [ - { - "proposalId": "1", - "voter": "cosmos1..", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ] - } - ], - "pagination": { - "total": "1" - } -} -``` - -#### Params - -The `Params` endpoint allows users to query all parameters for the `gov` module. - -Using legacy v1beta1: - -```bash -cosmos.gov.v1beta1.Query/Params -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"params_type":"voting"}' \ - localhost:9090 \ - cosmos.gov.v1beta1.Query/Params -``` - -Example Output: - -```bash -{ - "votingParams": { - "votingPeriod": "172800s" - }, - "depositParams": { - "maxDepositPeriod": "0s" - }, - "tallyParams": { - "quorum": "MA==", - "threshold": "MA==", - "vetoThreshold": "MA==" - } -} -``` - -Using v1: - -```bash -cosmos.gov.v1.Query/Params -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"params_type":"voting"}' \ - localhost:9090 \ - cosmos.gov.v1.Query/Params -``` - -Example Output: - -```bash -{ - "votingParams": { - "votingPeriod": "172800s" - } -} -``` - -#### Deposit - -The `Deposit` endpoint allows users to query a deposit for a given proposal from a given depositor. - -Using legacy v1beta1: - -```bash -cosmos.gov.v1beta1.Query/Deposit -``` - -Example: - -```bash -grpcurl -plaintext \ - '{"proposal_id":"1","depositor":"cosmos1.."}' \ - localhost:9090 \ - cosmos.gov.v1beta1.Query/Deposit -``` - -Example Output: - -```bash -{ - "deposit": { - "proposalId": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } -} -``` - -Using v1: - -```bash -cosmos.gov.v1.Query/Deposit -``` - -Example: - -```bash -grpcurl -plaintext \ - '{"proposal_id":"1","depositor":"cosmos1.."}' \ - localhost:9090 \ - cosmos.gov.v1.Query/Deposit -``` - -Example Output: - -```bash -{ - "deposit": { - "proposalId": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } -} -``` - -#### deposits - -The `Deposits` endpoint allows users to query all deposits for a given proposal. - -Using legacy v1beta1: - -```bash -cosmos.gov.v1beta1.Query/Deposits -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"proposal_id":"1"}' \ - localhost:9090 \ - cosmos.gov.v1beta1.Query/Deposits -``` - -Example Output: - -```bash -{ - "deposits": [ - { - "proposalId": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } - ], - "pagination": { - "total": "1" - } -} -``` - -Using v1: - -```bash -cosmos.gov.v1.Query/Deposits -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"proposal_id":"1"}' \ - localhost:9090 \ - cosmos.gov.v1.Query/Deposits -``` - -Example Output: - -```bash -{ - "deposits": [ - { - "proposalId": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } - ], - "pagination": { - "total": "1" - } -} -``` - -#### TallyResult - -The `TallyResult` endpoint allows users to query the tally of a given proposal. - -Using legacy v1beta1: - -```bash -cosmos.gov.v1beta1.Query/TallyResult -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"proposal_id":"1"}' \ - localhost:9090 \ - cosmos.gov.v1beta1.Query/TallyResult -``` - -Example Output: - -```bash -{ - "tally": { - "yes": "1000000", - "abstain": "0", - "no": "0", - "noWithVeto": "0", - "option_one_count": "1000000", - "option_two_count": "0", - "option_three_count": "0", - "option_four_count": "0", - "spam_count": "0" - } -} -``` - -Using v1: - -```bash -cosmos.gov.v1.Query/TallyResult -``` - -Example: - -```bash -grpcurl -plaintext \ - -d '{"proposal_id":"1"}' \ - localhost:9090 \ - cosmos.gov.v1.Query/TallyResult -``` - -Example Output: - -```bash -{ - "tally": { - "yes": "1000000", - "abstain": "0", - "no": "0", - "noWithVeto": "0" - } -} -``` - -### REST - -A user can query the `gov` module using REST endpoints. - -#### proposal - -The `proposals` endpoint allows users to query a given proposal. - -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id} -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1 -``` - -Example Output: - -```bash -{ - "proposal": { - "proposal_id": "1", - "content": null, - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "final_tally_result": { - "yes": "0", - "abstain": "0", - "no": "0", - "no_with_veto": "0" - }, - "submit_time": "2022-03-28T11:50:20.819676256Z", - "deposit_end_time": "2022-03-30T11:50:20.819676256Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10000000010" - } - ], - "voting_start_time": "2022-03-28T14:25:26.644857113Z", - "voting_end_time": "2022-03-30T14:25:26.644857113Z" - } -} -``` - -Using v1: +### REST + +A user can query the `gov` module using REST endpoints. + +#### proposal + +The `proposals` endpoint allows users to query a given proposal. ```bash /cosmos/gov/v1/proposals/{proposal_id} @@ -1849,121 +1194,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals/1 ``` -Example Output: - -```bash -{ - "proposal": { - "id": "1", - "messages": [ - { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": "cosmos1..", - "to_address": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10" - } - ] - } - ], - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "final_tally_result": { - "yes_count": "0", - "abstain_count": "0", - "no_count": "0", - "no_with_veto_count": "0" - }, - "submit_time": "2022-03-28T11:50:20.819676256Z", - "deposit_end_time": "2022-03-30T11:50:20.819676256Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10000000" - } - ], - "voting_start_time": "2022-03-28T14:25:26.644857113Z", - "voting_end_time": "2022-03-30T14:25:26.644857113Z", - "metadata": "AQ==", - "title": "Proposal Title", - "summary": "Proposal Summary" - } -} -``` - #### proposals The `proposals` endpoint also allows users to query all proposals with optional filters. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals -``` - -Example Output: - -```bash -{ - "proposals": [ - { - "proposal_id": "1", - "content": null, - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "final_tally_result": { - "yes": "0", - "abstain": "0", - "no": "0", - "no_with_veto": "0" - }, - "submit_time": "2022-03-28T11:50:20.819676256Z", - "deposit_end_time": "2022-03-30T11:50:20.819676256Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10000000" - } - ], - "voting_start_time": "2022-03-28T14:25:26.644857113Z", - "voting_end_time": "2022-03-30T14:25:26.644857113Z" - }, - { - "proposal_id": "2", - "content": null, - "status": "PROPOSAL_STATUS_DEPOSIT_PERIOD", - "final_tally_result": { - "yes": "0", - "abstain": "0", - "no": "0", - "no_with_veto": "0" - }, - "submit_time": "2022-03-28T14:02:41.165025015Z", - "deposit_end_time": "2022-03-30T14:02:41.165025015Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10" - } - ], - "voting_start_time": "0001-01-01T00:00:00Z", - "voting_end_time": "0001-01-01T00:00:00Z" - } - ], - "pagination": { - "next_key": null, - "total": "2" - } -} -``` - -Using v1: ```bash /cosmos/gov/v1/proposals @@ -1975,126 +1209,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals ``` -Example Output: - -```bash -{ - "proposals": [ - { - "id": "1", - "messages": [ - { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": "cosmos1..", - "to_address": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10" - } - ] - } - ], - "status": "PROPOSAL_STATUS_VOTING_PERIOD", - "final_tally_result": { - "yes_count": "0", - "abstain_count": "0", - "no_count": "0", - "no_with_veto_count": "0" - }, - "submit_time": "2022-03-28T11:50:20.819676256Z", - "deposit_end_time": "2022-03-30T11:50:20.819676256Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10000000010" - } - ], - "voting_start_time": "2022-03-28T14:25:26.644857113Z", - "voting_end_time": "2022-03-30T14:25:26.644857113Z", - "metadata": "AQ==", - "title": "Proposal Title", - "summary": "Proposal Summary" - }, - { - "id": "2", - "messages": [ - { - "@type": "/cosmos.bank.v1beta1.MsgSend", - "from_address": "cosmos1..", - "to_address": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10" - } - ] - } - ], - "status": "PROPOSAL_STATUS_DEPOSIT_PERIOD", - "final_tally_result": { - "yes_count": "0", - "abstain_count": "0", - "no_count": "0", - "no_with_veto_count": "0" - }, - "submit_time": "2022-03-28T14:02:41.165025015Z", - "deposit_end_time": "2022-03-30T14:02:41.165025015Z", - "total_deposit": [ - { - "denom": "stake", - "amount": "10" - } - ], - "voting_start_time": null, - "voting_end_time": null, - "metadata": "AQ==", - "title": "Proposal Title", - "summary": "Proposal Summary" - } - ], - "pagination": { - "next_key": null, - "total": "2" - } -} -``` - #### voter vote The `votes` endpoint allows users to query a vote for a given proposal. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id}/votes/{voter} -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1/votes/cosmos1.. -``` - -Example Output: - -```bash -{ - "vote": { - "proposal_id": "1", - "voter": "cosmos1..", - "option": "VOTE_OPTION_YES", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ] - } -} -``` - -Using v1: ```bash /cosmos/gov/v1/proposals/{proposal_id}/votes/{voter} @@ -2106,66 +1224,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals/1/votes/cosmos1.. ``` -Example Output: - -```bash -{ - "vote": { - "proposal_id": "1", - "voter": "cosmos1..", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ], - "metadata": "" - } -} -``` - #### votes The `votes` endpoint allows users to query all votes for a given proposal. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id}/votes -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1/votes -``` - -Example Output: - -```bash -{ - "votes": [ - { - "proposal_id": "1", - "voter": "cosmos1..", - "option": "VOTE_OPTION_YES", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ] - } - ], - "pagination": { - "next_key": null, - "total": "1" - } -} -``` - -Using v1: - ```bash /cosmos/gov/v1/proposals/{proposal_id}/votes ``` @@ -2176,58 +1238,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals/1/votes ``` -Example Output: - -```bash -{ - "votes": [ - { - "proposal_id": "1", - "voter": "cosmos1..", - "options": [ - { - "option": "VOTE_OPTION_YES", - "weight": "1.000000000000000000" - } - ], - "metadata": "" - } - ], - "pagination": { - "next_key": null, - "total": "1" - } -} -``` - #### params The `params` endpoint allows users to query all parameters for the `gov` module. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/params/{params_type} -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/params/voting -``` - -Example Output: - -```bash -{ - "voting_params": { - "voting_period": "172800s" - }, -} -``` - -Using v1: - ```bash /cosmos/gov/v1/params/{params_type} ``` @@ -2238,63 +1252,12 @@ Example: curl localhost:1317/cosmos/gov/v1/params/voting ``` -Example Output: - -```bash -{ - "voting_params": { - "voting_period": "172800s" - }, - "deposit_params": { - "min_deposit": [ - ], - "max_deposit_period": "0s" - }, - "tally_params": { - "quorum": "0.000000000000000000", - "threshold": "0.000000000000000000", - "veto_threshold": "0.000000000000000000" - } -} -``` - Note: `params_type` are deprecated in v1 since all params are stored in Params. #### deposits The `deposits` endpoint allows users to query a deposit for a given proposal from a given depositor. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id}/deposits/{depositor} -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1/deposits/cosmos1.. -``` - -Example Output: - -```bash -{ - "deposit": { - "proposal_id": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } -} -``` - -Using v1: - ```bash /cosmos/gov/v1/proposals/{proposal_id}/deposits/{depositor} ``` @@ -2305,64 +1268,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals/1/deposits/cosmos1.. ``` -Example Output: - -```bash -{ - "deposit": { - "proposal_id": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } -} -``` - #### proposal deposits The `deposits` endpoint allows users to query all deposits for a given proposal. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id}/deposits -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1/deposits -``` - -Example Output: - -```bash -{ - "deposits": [ - { - "proposal_id": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } - ], - "pagination": { - "next_key": null, - "total": "1" - } -} -``` - -Using v1: - ```bash /cosmos/gov/v1/proposals/{proposal_id}/deposits ``` @@ -2373,60 +1282,10 @@ Example: curl localhost:1317/cosmos/gov/v1/proposals/1/deposits ``` -Example Output: - -```bash -{ - "deposits": [ - { - "proposal_id": "1", - "depositor": "cosmos1..", - "amount": [ - { - "denom": "stake", - "amount": "10000000" - } - ] - } - ], - "pagination": { - "next_key": null, - "total": "1" - } -} -``` - #### tally The `tally` endpoint allows users to query the tally of a given proposal. -Using legacy v1beta1: - -```bash -/cosmos/gov/v1beta1/proposals/{proposal_id}/tally -``` - -Example: - -```bash -curl localhost:1317/cosmos/gov/v1beta1/proposals/1/tally -``` - -Example Output: - -```bash -{ - "tally": { - "yes": "1000000", - "abstain": "0", - "no": "0", - "no_with_veto": "0" - } -} -``` - -Using v1: - ```bash /cosmos/gov/v1/proposals/{proposal_id}/tally ``` @@ -2436,50 +1295,3 @@ Example: ```bash curl localhost:1317/cosmos/gov/v1/proposals/1/tally ``` - -Example Output: - -```bash -{ - "tally": { - "yes": "1000000", - "abstain": "0", - "no": "0", - "no_with_veto": "0" - } -} -``` - -## Metadata - -The gov module has two locations for metadata where users can provide further context about the on-chain actions they are taking. By default all metadata fields have a 255 character length field where metadata can be stored in json format, either on-chain or off-chain depending on the amount of data required. Here we provide a recommendation for the json structure and where the data should be stored. There are two important factors in making these recommendations. First, that the gov and group modules are consistent with one another, note the number of proposals made by all groups may be quite large. Second, that client applications such as block explorers and governance interfaces have confidence in the consistency of metadata structure across chains. - -### Proposal - -Location: off-chain as json object stored on IPFS (mirrors [group proposal](../group/README.md#metadata)) - -```json -{ - "title": "", - "authors": [""], - "summary": "", - "details": "", - "proposal_forum_url": "", - "vote_option_context": "", -} -``` - -:::note -The `authors` field is an array of strings, this is to allow for multiple authors to be listed in the metadata. -In v0.46, the `authors` field is a comma-separated string. Frontends are encouraged to support both formats for backwards compatibility. -::: - -### Vote - -Location: on-chain as json within 255 character limit (mirrors [group vote](../group/README.md#metadata)) - -```json -{ - "justification": "", -} -``` diff --git a/x/gov/go.mod b/x/gov/go.mod index dc3021ef7c57..f86ae5dcf8c6 100644 --- a/x/gov/go.mod +++ b/x/gov/go.mod @@ -127,7 +127,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/gov/go.sum b/x/gov/go.sum index 574d22fa7d26..46e0295dc4b6 100644 --- a/x/gov/go.sum +++ b/x/gov/go.sum @@ -420,8 +420,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/group/go.mod b/x/group/go.mod index 630c1350c6ba..6f83519f4085 100644 --- a/x/group/go.mod +++ b/x/group/go.mod @@ -133,7 +133,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/group/go.sum b/x/group/go.sum index f68efb396d8f..dbc625fc5f52 100644 --- a/x/group/go.sum +++ b/x/group/go.sum @@ -422,8 +422,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/group/keeper/abci.go b/x/group/keeper/abci.go index 6de580de74ba..c8d980375496 100644 --- a/x/group/keeper/abci.go +++ b/x/group/keeper/abci.go @@ -3,7 +3,7 @@ package keeper import ( "context" - "cosmossdk.io/x/gov/types" + "cosmossdk.io/x/group" "github.com/cosmos/cosmos-sdk/telemetry" ) @@ -12,7 +12,7 @@ import ( // prunes expired proposals. func (k Keeper) EndBlocker(ctx context.Context) error { start := telemetry.Now() - defer telemetry.ModuleMeasureSince(types.ModuleName, start, telemetry.MetricKeyEndBlocker) + defer telemetry.ModuleMeasureSince(group.ModuleName, start, telemetry.MetricKeyEndBlocker) if err := k.TallyProposalsAtVPEnd(ctx); err != nil { return err diff --git a/x/mint/go.mod b/x/mint/go.mod index 8692adb74660..b0343d16ef05 100644 --- a/x/mint/go.mod +++ b/x/mint/go.mod @@ -119,7 +119,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/mint/go.sum b/x/mint/go.sum index ceb6f972a420..c9df997e10ec 100644 --- a/x/mint/go.sum +++ b/x/mint/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/nft/README.md b/x/nft/README.md index 34c1d40660b9..3bf1b6b41b44 100644 --- a/x/nft/README.md +++ b/x/nft/README.md @@ -22,6 +22,8 @@ sidebar_position: 1 * [Messages](#messages) * [MsgSend](#msgsend) * [Events](#events) +* [Queries](#queries) +* [Keeper Functions](#keeper-functions) ## Concepts @@ -86,4 +88,30 @@ The message handling should fail if: ## Events -The nft module emits proto events defined in [the Protobuf reference](https://buf.build/cosmos/cosmos-sdk/docs/main:cosmos.nft.v1beta1). +The NFT module emits proto events defined in [the Protobuf reference](https://buf.build/cosmos/cosmos-sdk/docs/main:cosmos.nft.v1beta1). + +## Queries + +The `x/nft` module provides several queries to retrieve information about NFTs and classes: + +* `Balance`: Returns the number of NFTs of a given class owned by the owner. +* `Owner`: Returns the owner of an NFT based on its class and ID. +* `Supply`: Returns the number of NFTs from the given class. +* `NFTs`: Queries all NFTs of a given class or owner. +* `NFT`: Returns an NFT based on its class and ID. +* `Class`: Returns an NFT class based on its ID. +* `Classes`: Returns all NFT classes. + +## Keeper Functions + +The Keeper of the `x/nft` module provides several functions to manage NFTs: + +* `Mint`: Mints a new NFT. +* `Burn`: Burns an existing NFT. +* `Update`: Updates an existing NFT. +* `Transfer`: Transfers an NFT from one owner to another. +* `GetNFT`: Retrieves information about a specific NFT. +* `GetNFTsOfClass`: Retrieves all NFTs of a specific class. +* `GetNFTsOfClassByOwner`: Retrieves all NFTs of a specific class belonging to an owner. +* `GetBalance`: Retrieves the balance of NFTs of a specific class for an owner. +* `GetTotalSupply`: Retrieves the total supply of NFTs of a specific class. diff --git a/x/nft/go.mod b/x/nft/go.mod index a85590d7a2d4..baca50bed955 100644 --- a/x/nft/go.mod +++ b/x/nft/go.mod @@ -121,7 +121,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/nft/go.sum b/x/nft/go.sum index ceb6f972a420..c9df997e10ec 100644 --- a/x/nft/go.sum +++ b/x/nft/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/params/go.mod b/x/params/go.mod index b3e87ebb491d..f072f3b0256b 100644 --- a/x/params/go.mod +++ b/x/params/go.mod @@ -115,7 +115,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/params/go.sum b/x/params/go.sum index 865a6f73544b..048c9a1067ea 100644 --- a/x/params/go.sum +++ b/x/params/go.sum @@ -390,8 +390,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/protocolpool/go.mod b/x/protocolpool/go.mod index 620da3e271fc..5454bc67d0dd 100644 --- a/x/protocolpool/go.mod +++ b/x/protocolpool/go.mod @@ -122,7 +122,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/protocolpool/go.sum b/x/protocolpool/go.sum index ceb6f972a420..c9df997e10ec 100644 --- a/x/protocolpool/go.sum +++ b/x/protocolpool/go.sum @@ -414,8 +414,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/slashing/README.md b/x/slashing/README.md index c6da11e0ce2d..942b3afcc052 100644 --- a/x/slashing/README.md +++ b/x/slashing/README.md @@ -143,7 +143,7 @@ bonded validator. The `SignedBlocksWindow` parameter defines the size The information stored for tracking validator liveness is as follows: ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/slashing/proto/cosmos/slashing/v1beta1/slashing.proto#L13-L35 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/slashing/proto/cosmos/slashing/v1beta1/slashing.proto#L13-L35 ``` ### Params @@ -154,7 +154,7 @@ it can be updated with governance or the address with authority. * Params: `0x00 | ProtocolBuffer(Params)` ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/release/v0.52.x/x/slashing/proto/cosmos/slashing/v1beta1/slashing.proto#L37-L62 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/slashing/proto/cosmos/slashing/v1beta1/slashing.proto#L37-L62 ``` ## Messages @@ -312,6 +312,7 @@ The following hooks impact the slashing state: * `AfterValidatorBonded` creates a `ValidatorSigningInfo` instance as described in the following section. * `AfterValidatorCreated` stores a validator's consensus key. * `AfterValidatorRemoved` removes a validator's consensus key. +* `AfterConsensusPubKeyUpdate` handles the rotation of signing info and updates the address-pubkey relation after a consensus key update. ### Validator Bonded @@ -633,6 +634,20 @@ Example: simd tx slashing unjail --from mykey ``` +#### update-params-proposal + +The `update-params-proposal` command allows users to submit a governance proposal to update the slashing module parameters: + +```bash +simd tx slashing update-params-proposal [flags] +``` + +Example: + +```bash +simd tx slashing update-params-proposal '{ "signed_blocks_window": "100" }' +``` + ### gRPC A user can query the `slashing` module using gRPC endpoints. diff --git a/x/slashing/go.mod b/x/slashing/go.mod index 2d89e1d1c2d0..c207b1c5317b 100644 --- a/x/slashing/go.mod +++ b/x/slashing/go.mod @@ -124,7 +124,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/slashing/go.sum b/x/slashing/go.sum index 6ce353eda05c..9600563cd537 100644 --- a/x/slashing/go.sum +++ b/x/slashing/go.sum @@ -416,8 +416,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/staking/go.mod b/x/staking/go.mod index 2b0dc4f8ecce..9c4cdacb1257 100644 --- a/x/staking/go.mod +++ b/x/staking/go.mod @@ -111,7 +111,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect diff --git a/x/staking/go.sum b/x/staking/go.sum index d7ad42cc008f..7588b565a0d7 100644 --- a/x/staking/go.sum +++ b/x/staking/go.sum @@ -412,8 +412,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= diff --git a/x/tx/CHANGELOG.md b/x/tx/CHANGELOG.md index da689199910d..9fc07fac5acf 100644 --- a/x/tx/CHANGELOG.md +++ b/x/tx/CHANGELOG.md @@ -33,8 +33,7 @@ Since v0.13.0, x/tx follows Cosmos SDK semver: https://github.com/cosmos/cosmos- ## [Unreleased] -### Improvements - +* [#21825](https://github.com/cosmos/cosmos-sdk/pull/21825) Fix decimal encoding and field ordering in Amino JSON encoder. * [#21850](https://github.com/cosmos/cosmos-sdk/pull/21850) Support bytes field as signer. ## [v0.13.5](https://github.com/cosmos/cosmos-sdk/releases/tag/x/tx/v0.13.5) - 2024-09-18 diff --git a/x/tx/go.mod b/x/tx/go.mod index 9d1bab0a9553..ed82d6892f5a 100644 --- a/x/tx/go.mod +++ b/x/tx/go.mod @@ -4,7 +4,7 @@ go 1.23 require ( cosmossdk.io/api v0.7.6 - cosmossdk.io/core v1.0.0-alpha.3 + cosmossdk.io/core v1.0.0-alpha.4 cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 github.com/cosmos/cosmos-proto v1.0.0-beta.5 diff --git a/x/tx/go.sum b/x/tx/go.sum index 86e1a66db153..d92c41b50631 100644 --- a/x/tx/go.sum +++ b/x/tx/go.sum @@ -1,7 +1,7 @@ cosmossdk.io/api v0.7.6 h1:PC20PcXy1xYKH2KU4RMurVoFjjKkCgYRbVAD4PdqUuY= cosmossdk.io/api v0.7.6/go.mod h1:IcxpYS5fMemZGqyYtErK7OqvdM0C8kdW3dq8Q/XIG38= -cosmossdk.io/core v1.0.0-alpha.3 h1:pnxaYAas7llXgVz1lM7X6De74nWrhNKnB3yMKe4OUUA= -cosmossdk.io/core v1.0.0-alpha.3/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= +cosmossdk.io/core v1.0.0-alpha.4 h1:9iuroT9ejDYETCsGkzkvs/wAY/5UFl7nCIINFRxyMJY= +cosmossdk.io/core v1.0.0-alpha.4/go.mod h1:3u9cWq1FAVtiiCrDPpo4LhR+9V6k/ycSG4/Y/tREWCY= cosmossdk.io/errors v1.0.1 h1:bzu+Kcr0kS/1DuPBtUFdWjzLqyUuCiyHjyJB6srBV/0= cosmossdk.io/errors v1.0.1/go.mod h1:MeelVSZThMi4bEakzhhhE/CKqVv3nOJDA25bIqRDu/U= cosmossdk.io/math v1.3.0 h1:RC+jryuKeytIiictDslBP9i1fhkVm6ZDmZEoNP316zE= diff --git a/x/tx/signing/aminojson/encoder.go b/x/tx/signing/aminojson/encoder.go index 9fe589c0e544..d3e1e75c8bba 100644 --- a/x/tx/signing/aminojson/encoder.go +++ b/x/tx/signing/aminojson/encoder.go @@ -51,7 +51,12 @@ func cosmosDecEncoder(_ *Encoder, v protoreflect.Value, w io.Writer) error { if val == "" { return jsonMarshal(w, "0") } - return jsonMarshal(w, val) + var dec math.LegacyDec + err := dec.Unmarshal([]byte(val)) + if err != nil { + return err + } + return jsonMarshal(w, dec.String()) case []byte: if len(val) == 0 { return jsonMarshal(w, "0") @@ -125,27 +130,40 @@ func keyFieldEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) error { } type moduleAccountPretty struct { - Address string `json:"address"` - PubKey string `json:"public_key"` AccountNumber uint64 `json:"account_number"` - Sequence uint64 `json:"sequence"` + Address string `json:"address"` Name string `json:"name"` Permissions []string `json:"permissions"` + PubKey string `json:"public_key"` + Sequence uint64 `json:"sequence"` } // moduleAccountEncoder replicates the behavior in // https://github.com/cosmos/cosmos-sdk/blob/41a3dfeced2953beba3a7d11ec798d17ee19f506/x/auth/types/account.go#L230-L254 func moduleAccountEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) error { - ma := msg.Interface().(*authapi.ModuleAccount) + ma := &authapi.ModuleAccount{} + msgDesc := msg.Descriptor() + if msgDesc.FullName() != ma.ProtoReflect().Descriptor().FullName() { + return errors.New("moduleAccountEncoder: msg not a auth.ModuleAccount") + } + fields := msgDesc.Fields() + pretty := moduleAccountPretty{ - PubKey: "", - Name: ma.Name, - Permissions: ma.Permissions, - } - if ma.BaseAccount != nil { - pretty.Address = ma.BaseAccount.Address - pretty.AccountNumber = ma.BaseAccount.AccountNumber - pretty.Sequence = ma.BaseAccount.Sequence + PubKey: "", + Name: msg.Get(fields.ByName("name")).String(), + } + permissions := msg.Get(fields.ByName("permissions")).List() + for i := 0; i < permissions.Len(); i++ { + pretty.Permissions = append(pretty.Permissions, permissions.Get(i).String()) + } + + if msg.Has(fields.ByName("base_account")) { + baseAccount := msg.Get(fields.ByName("base_account")) + baMsg := baseAccount.Message() + bamdFields := baMsg.Descriptor().Fields() + pretty.Address = baMsg.Get(bamdFields.ByName("address")).String() + pretty.AccountNumber = baMsg.Get(bamdFields.ByName("account_number")).Uint() + pretty.Sequence = baMsg.Get(bamdFields.ByName("sequence")).Uint() } else { pretty.Address = "" pretty.AccountNumber = 0 @@ -166,29 +184,34 @@ func moduleAccountEncoder(_ *Encoder, msg protoreflect.Message, w io.Writer) err // also see: // https://github.com/cosmos/cosmos-sdk/blob/b49f948b36bc991db5be431607b475633aed697e/proto/cosmos/crypto/multisig/keys.proto#L15/ func thresholdStringEncoder(enc *Encoder, msg protoreflect.Message, w io.Writer) error { - pk, ok := msg.Interface().(*multisig.LegacyAminoPubKey) - if !ok { + pk := &multisig.LegacyAminoPubKey{} + msgDesc := msg.Descriptor() + fields := msgDesc.Fields() + if msgDesc.FullName() != pk.ProtoReflect().Descriptor().FullName() { return errors.New("thresholdStringEncoder: msg not a multisig.LegacyAminoPubKey") } - _, err := fmt.Fprintf(w, `{"threshold":"%d","pubkeys":`, pk.Threshold) - if err != nil { - return err - } - if len(pk.PublicKeys) == 0 { - _, err = io.WriteString(w, `[]}`) - return err - } - - fields := msg.Descriptor().Fields() pubkeysField := fields.ByName("public_keys") pubkeys := msg.Get(pubkeysField).List() - err = enc.marshalList(pubkeys, pubkeysField, w) + _, err := io.WriteString(w, `{"pubkeys":`) if err != nil { return err } - _, err = io.WriteString(w, `}`) + if pubkeys.Len() == 0 { + _, err := io.WriteString(w, `[]`) + if err != nil { + return err + } + } else { + err := enc.marshalList(pubkeys, pubkeysField, w) + if err != nil { + return err + } + } + + threshold := fields.ByName("threshold") + _, err = fmt.Fprintf(w, `,"threshold":"%d"}`, msg.Get(threshold).Uint()) return err } diff --git a/x/upgrade/README.md b/x/upgrade/README.md index 81534d422694..9e9c41e8ccc9 100644 --- a/x/upgrade/README.md +++ b/x/upgrade/README.md @@ -106,7 +106,7 @@ the `Plan`, which targets a specific `Handler`, is persisted and scheduled. The upgrade can be delayed or hastened by updating the `Plan.Height` in a new proposal. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/upgrade/v1beta1/tx.proto#L29-L41 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/upgrade/proto/cosmos/upgrade/v1beta1/tx.proto#L29-L40 ``` #### Cancelling Upgrade Proposals @@ -118,7 +118,7 @@ Of course this requires that the upgrade was known to be a bad idea well before upgrade itself, to allow time for a vote. ```protobuf reference -https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/proto/cosmos/upgrade/v1beta1/tx.proto#L48-L57 +https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/upgrade/proto/cosmos/upgrade/v1beta1/tx.proto#L47-L55 ``` If such a possibility is desired, the upgrade height is to be @@ -315,6 +315,28 @@ time: "0001-01-01T00:00:00Z" upgraded_client_state: null ``` +##### authority + +The `authority` command allows users to query the address that is authorized to submit upgrade proposals. + +```bash +simd query upgrade authority [flags] +``` + +This command returns the bech32-encoded address of the account that has the authority to submit upgrade proposals. + +Example: + +```bash +simd query upgrade authority +``` + +Example Output: + +```bash +cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn +``` + #### Transactions The upgrade module supports the following transactions: @@ -326,10 +348,10 @@ simd tx upgrade software-upgrade v2 --title="Test Proposal" --summary="testing" --upgrade-info '{ "binaries": { "linux/amd64":"https://example.com/simd.zip?checksum=sha256:aec070645fe53ee3b3763059376134f058cc337247c978add178b6ccdfb0019f" } }' --from cosmos1.. ``` -* `cancel-software-upgrade` - cancels a previously submitted upgrade proposal: +* `cancel-upgrade-proposal` - cancels a previously submitted upgrade proposal: ```bash -simd tx upgrade cancel-software-upgrade --title="Test Proposal" --summary="testing" --deposit="100000000stake" --from cosmos1.. +simd tx upgrade cancel-upgrade-proposal --title="Test Proposal" --summary="testing" --deposit="100000000stake" --from cosmos1.. ``` ### REST @@ -467,6 +489,28 @@ Example Output: } ``` +#### Authority + +`Authority` queries the address that is authorized to submit upgrade proposals. + +```bash +/cosmos/upgrade/v1beta1/authority +``` + +Example: + +```bash +curl -X GET "http://localhost:1317/cosmos/upgrade/v1beta1/authority" -H "accept: application/json" +``` + +Example Output: + +```json +{ +"address": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" +} +``` + ### gRPC A user can query the `upgrade` module using gRPC endpoints. @@ -507,7 +551,7 @@ cosmos.upgrade.v1beta1.Query/CurrentPlan Example: ```bash -grpcurl -plaintext localhost:9090 cosmos.slashing.v1beta1.Query/CurrentPlan +grpcurl -plaintext localhost:9090 cosmos.upgrade.v1beta1.Query/CurrentPlan ``` Example Output: @@ -529,7 +573,7 @@ cosmos.upgrade.v1beta1.Query/ModuleVersions Example: ```bash -grpcurl -plaintext localhost:9090 cosmos.slashing.v1beta1.Query/ModuleVersions +grpcurl -plaintext localhost:9090 cosmos.upgrade.v1beta1.Query/ModuleVersions ``` Example Output: @@ -605,6 +649,28 @@ Example Output: } ``` +#### Authority + +`Authority` queries the address that is authorized to submit upgrade proposals. + +```bash +cosmos.upgrade.v1beta1.Query/Authority +``` + +Example: + +```bash +grpcurl -plaintext localhost:9090 cosmos.upgrade.v1beta1.Query/Authority +``` + +Example Output: + +```json +{ + "address": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn" +} +``` + ## Resources A list of (external) resources to learn more about the `x/upgrade` module. diff --git a/x/upgrade/go.mod b/x/upgrade/go.mod index 4f43ab99188a..6505f6b4b02a 100644 --- a/x/upgrade/go.mod +++ b/x/upgrade/go.mod @@ -147,7 +147,7 @@ require ( github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/prometheus/client_golang v1.20.4 // indirect github.com/prometheus/client_model v0.6.1 // indirect - github.com/prometheus/common v0.59.1 // indirect + github.com/prometheus/common v0.60.0 // indirect github.com/prometheus/procfs v0.15.1 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect github.com/rogpeppe/go-internal v1.12.0 // indirect @@ -181,7 +181,7 @@ require ( golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.29.0 // indirect - golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.8.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/term v0.24.0 // indirect diff --git a/x/upgrade/go.sum b/x/upgrade/go.sum index 71a7d822e97c..257f52f8aca0 100644 --- a/x/upgrade/go.sum +++ b/x/upgrade/go.sum @@ -722,8 +722,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= github.com/prometheus/common v0.9.1/go.mod h1:yhUN8i9wzaXS3w1O07YhxHEBxD+W35wd8bs7vj7HSQ4= -github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= -github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= +github.com/prometheus/common v0.60.0 h1:+V9PAREWNvJMAuJ1x1BaWl9dewMW4YrHZQbx0sJNllA= +github.com/prometheus/common v0.60.0/go.mod h1:h0LYf1R1deLSKtD4Vdg8gy4RuOvENW2J/h19V5NADQw= github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A= @@ -972,8 +972,8 @@ golang.org/x/oauth2 v0.0.0-20220822191816-0ebed06d0094/go.mod h1:h4gKUeWbJ4rQPri golang.org/x/oauth2 v0.0.0-20220909003341-f21342109be1/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783/go.mod h1:h4gKUeWbJ4rQPri7E0u6Gs4e9Ri2zaLxzw5DI5XGrYg= golang.org/x/oauth2 v0.1.0/go.mod h1:G9FE4dLTsbXUu90h/Pf85g4w1D+SSAgR+q46nJZ8M4A= -golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= -golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs= +golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=