Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events Tracking / Tendermint v0.32.0 Update #4541

Merged
merged 63 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
16becae
Update Tendermint to v0.32.0-dev0
alexanderbez Jun 12, 2019
7b36391
Initial refactor of tags
alexanderbez Jun 13, 2019
3540f58
Update event types and add unit tests
alexanderbez Jun 13, 2019
dbe1ceb
Refactor context
alexanderbez Jun 18, 2019
d7fff33
Update module manager
alexanderbez Jun 18, 2019
0319670
Update result godoc
alexanderbez Jun 18, 2019
f57c994
Implement ToABCIEvents
alexanderbez Jun 18, 2019
f65a30a
Update BaseApp
alexanderbez Jun 18, 2019
55e340f
Minor cleanup
alexanderbez Jun 18, 2019
0114e94
Fix typo
alexanderbez Jun 18, 2019
c4496b4
Update x/bank message handler
alexanderbez Jun 18, 2019
63d312e
Update x/bank keeper
alexanderbez Jun 18, 2019
f08b526
Update x/bank
alexanderbez Jun 18, 2019
b1dd734
Update x/bank events docs
alexanderbez Jun 18, 2019
e7bad6b
Update x/crisis module events
alexanderbez Jun 18, 2019
f7706ee
Reset context with events on each message exec
alexanderbez Jun 19, 2019
66b3b1a
Update x/distribution events and docs
alexanderbez Jun 19, 2019
fb7b8ba
Update BaseApp to not set empty events manually
alexanderbez Jun 19, 2019
2ec93d7
Implement simple event manager
alexanderbez Jun 19, 2019
27a80bc
Update module manager
alexanderbez Jun 19, 2019
3e3d95d
Update modules to use event manager
alexanderbez Jun 19, 2019
79190db
Update x/gov module to use events
alexanderbez Jun 19, 2019
a690ab0
Update events docs
alexanderbez Jun 19, 2019
6b5e9fa
Update gov queries and crisis app module
alexanderbez Jun 19, 2019
bc7074c
Update bank keeper
alexanderbez Jun 19, 2019
3b10232
Add events to minting begin blocker
alexanderbez Jun 19, 2019
d0f1bc0
Update modules to use types/events.go
alexanderbez Jun 19, 2019
10d733f
Merge branch 'master' into bez/4387-events-tracking
alexanderbez Jun 19, 2019
0469eee
Cleanup x/mint
alexanderbez Jun 20, 2019
e22a64f
Update x/staking events
alexanderbez Jun 20, 2019
e2b022b
Update x/staking events
alexanderbez Jun 20, 2019
82a4629
Update events to have sender part of message.sender
alexanderbez Jun 20, 2019
0952ada
Fix build
alexanderbez Jun 20, 2019
e5eba24
Fix module unit tests
alexanderbez Jun 20, 2019
d32d86c
Merge branch 'master' into bez/4387-events-tracking
alexanderbez Jun 20, 2019
ced1c35
Add pending log entry
alexanderbez Jun 20, 2019
0d8228c
Update deps
alexanderbez Jun 20, 2019
0e303ed
Update x/crisis/types/events.go
alexanderbez Jun 20, 2019
4f8b897
Update x/bank/internal/types/events.go
alexanderbez Jun 20, 2019
ca98591
Update x/distribution/types/events.go
alexanderbez Jun 20, 2019
035907d
Update x/mint/internal/types/events.go
alexanderbez Jun 20, 2019
508f645
Update x/slashing/types/events.go
alexanderbez Jun 20, 2019
1cbffbf
Update x/staking/types/events.go
alexanderbez Jun 20, 2019
6d8bdd8
Update x/gov/handler.go
alexanderbez Jun 20, 2019
88c4d24
Update x/gov/handler.go
alexanderbez Jun 20, 2019
2532c0c
Update x/mint/abci.go
alexanderbez Jun 20, 2019
dd5ed71
Update x/mint/abci.go
alexanderbez Jun 20, 2019
d98cb35
Update x/slashing/handler.go
alexanderbez Jun 20, 2019
cd05107
Update x/staking/handler.go
alexanderbez Jun 20, 2019
237e8f6
Update x/slashing/handler.go
alexanderbez Jun 20, 2019
61e2ca5
Update x/staking/handler.go
alexanderbez Jun 20, 2019
cb192e0
Update x/staking/handler.go
alexanderbez Jun 20, 2019
9fe5e7b
Update x/staking/handler.go
alexanderbez Jun 20, 2019
861ea2b
Upgrade TM to v0.32.0-dev1
alexanderbez Jun 21, 2019
4afdf7c
Update events as strings
alexanderbez Jun 21, 2019
92c65da
Update Tendermint to v0.32.0-dev2
alexanderbez Jun 24, 2019
6f1a3c6
Merge branch 'master' into bez/4387-events-tracking
alexanderbez Jun 24, 2019
0ce332c
Fix BaseApp unit tests
alexanderbez Jun 24, 2019
3f83ae6
Fix unit tests
alexanderbez Jun 24, 2019
8a40d54
Merge branch 'master' into bez/4387-events-tracking
alexanderbez Jun 25, 2019
a1ca784
Bump tendermint version to v0.32.0
alexanderbez Jun 26, 2019
68dc986
Merge branch 'master' into bez/4387-events-tracking
alexanderbez Jun 26, 2019
a70bb31
typos
rigelrozanski Jun 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved

| 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