Skip to content

Commit

Permalink
Merge PR #4541: Events Tracking / Tendermint v0.32.0 Update
Browse files Browse the repository at this point in the history
* Update Tendermint to v0.32.0-dev0

* Initial refactor of tags

* Update event types and add unit tests

* Refactor context

* Update module manager

* Update result godoc

* Implement ToABCIEvents

* Update BaseApp

* Minor cleanup

* Fix typo

* Update x/bank message handler

* Update x/bank keeper

* Update x/bank

* Update x/bank events docs

* Update x/crisis module events

* Reset context with events on each message exec

* Update x/distribution events and docs

* Update BaseApp to not set empty events manually

* Implement simple event manager

* Update module manager

* Update modules to use event manager

* Update x/gov module to use events

* Update events docs

* Update gov queries and crisis app module

* Update bank keeper

* Add events to minting begin blocker

* Update modules to use types/events.go

* Cleanup x/mint

* Update x/staking events

* Update x/staking events

* Update events to have sender part of message.sender

* Fix build

* Fix module unit tests

* Add pending log entry

* Update deps

* Update x/crisis/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/bank/internal/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/distribution/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/mint/internal/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/slashing/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/staking/types/events.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/gov/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/gov/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/mint/abci.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/mint/abci.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/slashing/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/staking/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/slashing/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/staking/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/staking/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update x/staking/handler.go

Co-Authored-By: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Upgrade TM to v0.32.0-dev1

* Update events as strings

* Update Tendermint to v0.32.0-dev2

* Fix BaseApp unit tests

* Fix unit tests

* Bump tendermint version to v0.32.0

* typos
  • Loading branch information
alexanderbez authored and rigelrozanski committed Jun 26, 2019
1 parent 3950017 commit 67f6b02
Show file tree
Hide file tree
Showing 89 changed files with 1,306 additions and 972 deletions.
15 changes: 15 additions & 0 deletions .pending/breaking/sdk/4387-Refactor-the-us
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#4387 Refactor the usage of tags (now called events) to reflect the
new ABCI events semantics:

- Move `x/{module}/tags/tags.go` => `x/{module}/types/events.go`
- Update `docs/specs`
- Refactor tags in favor of new `Event(s)` type(s)
- Update `Context` to use new `EventManager`
- (Begin|End)Blocker no longer return tags, but rather uses new `EventManager`
- Message handlers no longer return tags, but rather uses new `EventManager`

Any component (e.g. BeginBlocker, message handler, etc...) wishing to emit an event must do so
through `ctx.EventManger().EmitEvent(s)`.

To reset or wipe emitted events: `ctx = ctx.WithEventManager(sdk.NewEventManager())`
To get all emitted events: `events := ctx.EventManager().Events()`
41 changes: 23 additions & 18 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,14 +627,14 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
// the route match to see whether a handler exists.
//
// NOTE:CheckTx does not run the actual Msg handler function(s).
func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
func (app *BaseApp) CheckTx(req abci.RequestCheckTx) (res abci.ResponseCheckTx) {
var result sdk.Result

tx, err := app.txDecoder(txBytes)
tx, err := app.txDecoder(req.Tx)
if err != nil {
result = err.Result()
} else {
result = app.runTx(runTxModeCheck, txBytes, tx)
result = app.runTx(runTxModeCheck, req.Tx, tx)
}

return abci.ResponseCheckTx{
Expand All @@ -643,19 +643,19 @@ func (app *BaseApp) CheckTx(txBytes []byte) (res abci.ResponseCheckTx) {
Log: result.Log,
GasWanted: int64(result.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(result.GasUsed), // TODO: Should type accept unsigned ints?
Tags: result.Tags,
Events: result.Events.ToABCIEvents(),
}
}

// DeliverTx implements the ABCI interface.
func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) {
var result sdk.Result

tx, err := app.txDecoder(txBytes)
tx, err := app.txDecoder(req.Tx)
if err != nil {
result = err.Result()
} else {
result = app.runTx(runTxModeDeliver, txBytes, tx)
result = app.runTx(runTxModeDeliver, req.Tx, tx)
}

return abci.ResponseDeliverTx{
Expand All @@ -665,7 +665,7 @@ func (app *BaseApp) DeliverTx(txBytes []byte) (res abci.ResponseDeliverTx) {
Log: result.Log,
GasWanted: int64(result.GasWanted), // TODO: Should type accept unsigned ints?
GasUsed: int64(result.GasUsed), // TODO: Should type accept unsigned ints?
Tags: result.Tags,
Events: result.Events.ToABCIEvents(),
}
}

Expand Down Expand Up @@ -705,11 +705,15 @@ func (app *BaseApp) getContextForTx(mode runTxMode, txBytes []byte) (ctx sdk.Con
func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (result sdk.Result) {
idxLogs := make([]sdk.ABCIMessageLog, 0, len(msgs)) // a list of JSON-encoded logs with msg index

var data []byte // NOTE: we just append them all (?!)
var tags sdk.Tags // also just append them all
var code sdk.CodeType
var codespace sdk.CodespaceType
var (
data []byte
code sdk.CodeType
codespace sdk.CodespaceType
)

events := sdk.EmptyEvents()

// NOTE: GasWanted is determined by ante handler and GasUsed by the GasMeter.
for msgIdx, msg := range msgs {
// match message route
msgRoute := msg.Route()
Expand All @@ -725,12 +729,13 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
msgResult = handler(ctx, msg)
}

// NOTE: GasWanted is determined by ante handler and GasUsed by the GasMeter.

// Result.Data must be length prefixed in order to separate each result
// Each message result's Data must be length prefixed in order to separate
// each result.
data = append(data, msgResult.Data...)
tags = append(tags, sdk.MakeTag(sdk.TagAction, msg.Type()))
tags = append(tags, msgResult.Tags...)

// append events from the message's execution and a message action event
events = events.AppendEvent(sdk.NewEvent(sdk.EventTypeMessage, sdk.NewAttribute(sdk.AttributeKeyAction, msg.Type())))
events = events.AppendEvents(msgResult.Events)

idxLog := sdk.ABCIMessageLog{MsgIndex: uint16(msgIdx), Log: msgResult.Log}

Expand All @@ -755,7 +760,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, mode runTxMode) (re
Data: data,
Log: strings.TrimSpace(string(logJSON)),
GasUsed: ctx.GasMeter().GasConsumed(),
Tags: tags,
Events: events,
}

return result
Expand Down
20 changes: 10 additions & 10 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ func TestCheckTx(t *testing.T) {
tx := newTxCounter(i, 0)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
r := app.CheckTx(txBytes)
r := app.CheckTx(abci.RequestCheckTx{Tx: txBytes})
assert.True(t, r.IsOK(), fmt.Sprintf("%v", r))
}

Expand Down Expand Up @@ -607,7 +607,7 @@ func TestDeliverTx(t *testing.T) {
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)

res := app.DeliverTx(txBytes)
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))
}

Expand Down Expand Up @@ -650,7 +650,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
tx := newTxCounter(0, 0, 1, 2)
txBytes, err := codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res := app.DeliverTx(txBytes)
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

store := app.deliverState.ctx.KVStore(capKey1)
Expand All @@ -670,7 +670,7 @@ func TestMultiMsgDeliverTx(t *testing.T) {
tx.Msgs = append(tx.Msgs, msgCounter2{1})
txBytes, err = codec.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res = app.DeliverTx(txBytes)
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

store = app.deliverState.ctx.KVStore(capKey1)
Expand Down Expand Up @@ -836,7 +836,7 @@ func TestRunInvalidTransaction(t *testing.T) {

txBytes, err := newCdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res := app.DeliverTx(txBytes)
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.EqualValues(t, sdk.CodeTxDecode, res.Code)
require.EqualValues(t, sdk.CodespaceRoot, res.Codespace)
}
Expand Down Expand Up @@ -1055,7 +1055,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
tx.setFailOnAnte(true)
txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)
res := app.DeliverTx(txBytes)
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))

ctx := app.getState(runTxModeDeliver).ctx
Expand All @@ -1070,7 +1070,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)

res = app.DeliverTx(txBytes)
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))

ctx = app.getState(runTxModeDeliver).ctx
Expand All @@ -1085,7 +1085,7 @@ func TestBaseAppAnteHandler(t *testing.T) {
txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)

res = app.DeliverTx(txBytes)
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.True(t, res.IsOK(), fmt.Sprintf("%v", res))

ctx = app.getState(runTxModeDeliver).ctx
Expand Down Expand Up @@ -1161,15 +1161,15 @@ func TestGasConsumptionBadTx(t *testing.T) {
txBytes, err := cdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)

res := app.DeliverTx(txBytes)
res := app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))

// require next tx to fail due to black gas limit
tx = newTxCounter(5, 0)
txBytes, err = cdc.MarshalBinaryLengthPrefixed(tx)
require.NoError(t, err)

res = app.DeliverTx(txBytes)
res = app.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
require.False(t, res.IsOK(), fmt.Sprintf("%v", res))
}

Expand Down
23 changes: 23 additions & 0 deletions docs/spec/bank/04_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Events

The bank module emits the following events:

## Handlers

### MsgSend

| Type | Attribute Key | Attribute Value |
|----------|---------------|--------------------|
| transfer | recipient | {recipientAddress} |
| message | module | bank |
| message | action | send |
| message | sender | {senderAddress} |

### MsgMultiSend

| Type | Attribute Key | Attribute Value |
|----------|---------------|--------------------|
| transfer | recipient | {recipientAddress} |
| message | module | bank |
| message | action | multisend |
| message | sender | {senderAddress} |
23 changes: 0 additions & 23 deletions docs/spec/bank/04_tags.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/spec/bank/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ This module will be used in the Cosmos Hub.
- [ViewKeeper](02_keepers.md#viewkeeper)
3. **[Messages](03_messages.md)**
- [MsgSend](03_messages.md#msgsend)
4. **[Tags](04_tags.md)**
- [Handlers](04_tags.md#handlers)
4. **[Events](04_events.md)**
- [Handlers](04_events.md#handlers)
5. **[Parameters](05_params.md)**
14 changes: 14 additions & 0 deletions docs/spec/crisis/03_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Events

The crisis module emits the following events:

## Handlers

### MsgVerifyInvariance

| Type | Attribute Key | Attribute Value |
|-----------|---------------|------------------|
| invariant | route | {invariantRoute} |
| message | module | crisis |
| message | action | verify_invariant |
| message | sender | {senderAddress} |
14 changes: 0 additions & 14 deletions docs/spec/crisis/03_tags.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/spec/crisis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ application initialization process.
- [ConstantFee](01_state.md#constantfee)
2. **[Messages](02_messages.md)**
- [MsgVerifyInvariant](02_messages.md#msgverifyinvariant)
3. **[Tags](03_tags.md)**
- [Handlers](03_tags.md#handlers)
3. **[Events](03_events.md)**
- [Handlers](03_events.md#handlers)
4. **[Parameters](04_params.md)**
44 changes: 44 additions & 0 deletions docs/spec/distribution/06_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Events

The distribution module emits the following events:

## BeginBlocker

| Type | Attribute Key | Attribute Value |
|-----------------|---------------|--------------------|
| proposer_reward | validator | {validatorAddress} |
| proposer_reward | reward | {proposerReward} |
| commission | amount | {commissionAmount} |
| commission | validator | {validatorAddress} |
| rewards | amount | {rewardAmount} |
| rewards | validator | {validatorAddress} |

## Handlers

### MsgSetWithdrawAddress

| Type | Attribute Key | Attribute Value |
|----------------------|------------------|----------------------|
| set_withdraw_address | withdraw_address | {withdrawAddress} |
| message | module | distribution |
| message | action | set_withdraw_address |
| message | sender | {senderAddress} |

### MsgWithdrawDelegatorReward

| Type | Attribute Key | Attribute Value |
|---------|---------------|---------------------------|
| withdraw_rewards | amount | {rewardAmount} |
| withdraw_rewards | validator | {validatorAddress} |
| message | module | distribution |
| message | action | withdraw_delegator_reward |
| message | sender | {senderAddress} |

### MsgWithdrawValidatorCommission

| Type | Attribute Key | Attribute Value |
|------------|---------------|-------------------------------|
| withdraw_commission | amount | {commissionAmount} |
| message | module | distribution |
| message | action | withdraw_validator_commission |
| message | sender | {senderAddress} |
32 changes: 0 additions & 32 deletions docs/spec/distribution/06_tags.md

This file was deleted.

5 changes: 3 additions & 2 deletions docs/spec/distribution/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ to set up a script to periodically withdraw and rebond rewards.
- [Create or modify delegation distribution](05_hooks.md#create-or-modify-delegation-distribution)
- [Commission rate change](05_hooks.md#commission-rate-change)
- [Change in Validator State](05_hooks.md#change-in-validator-state)
6. **[Tags](06_tags.md)**
- [Handlers](06_tags.md#handlers)
6. **[Events](06_events.md)**
- [BeginBlocker](06_events.md#beginblocker)
- [Handlers](06_events.md#handlers)
7. **[Parameters](07_params.md)**
Loading

0 comments on commit 67f6b02

Please sign in to comment.