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

83 emit state update event #91

Merged
merged 6 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
70 changes: 70 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20280,6 +20280,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/rollapp/block_height_to_finalization_queue/{finalizationHeight}':
Expand Down Expand Up @@ -20506,6 +20516,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/rollapp/latest_state_info_index/{rollappId}':
Expand Down Expand Up @@ -20798,6 +20818,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/rollapp/rollapp/{rollappId}':
Expand Down Expand Up @@ -21118,6 +21148,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/rollapp/state_info/{rollappId}/{index}':
Expand Down Expand Up @@ -21768,6 +21808,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/sequencer/scheduler/{sequencerAddress}':
Expand Down Expand Up @@ -22492,6 +22542,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/sequencer/sequencer/{sequencerAddress}':
Expand Down Expand Up @@ -23215,6 +23275,16 @@ paths:
in: query
required: false
type: boolean
- name: pagination.reverse
description: >-
reverse is set to true if results are to be returned in the
descending order.


Since: cosmos-sdk 0.43
in: query
required: false
type: boolean
tags:
- Query
'/dymensionxyz/dymension/sequencer/sequencers_by_rollapp/{rollappId}':
Expand Down
37 changes: 4 additions & 33 deletions scripts/run_local.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,40 +1,11 @@
#!/bin/sh

# .................................................... #
# ...........Set and validate parameters.............. #
# .................................................... #
DATA_DIRECTORY="$HOME/.dymension"
CONFIG_DIRECTORY="$DATA_DIRECTORY/config"
CLIENT_CONFIG_FILE="$CONFIG_DIRECTORY/client.toml"
GENESIS_FILE="$CONFIG_DIRECTORY/genesis.json"
CHAIN_ID=${CHAIN_ID:-"local-testnet"}
MONIKER_NAME=${MONIKER_NAME:-"local"}
KEY_NAME=${KEY_NAME:-"local-user"}

# Validate necessary data is exists
export PATH=$PATH:$HOME/go/bin
if ! command -v dymd; then
echo "dYmension binary not found, call \"make install\"."
if ! command -v dymd || [ ! -f "$HOME/.dymension/config/genesis.json" ]; then
echo "dYmension binary or genesis file are not exists, run 'setup_local.sh' before"
exit 1
fi

# ...................................................... #
# ............... Init dymension chain ................. #
# ...................................................... #
if [ ! -f "$GENESIS_FILE" ]; then
dymd init "$MONIKER_NAME" --chain-id="$CHAIN_ID"
dymd tendermint unsafe-reset-all

sed -i'' -e "s/^chain-id *= .*/chain-id = \"$CHAIN_ID\"/" "$CLIENT_CONFIG_FILE"
sed -i'' -e 's/bond_denom": ".*"/bond_denom": "dym"/' "$GENESIS_FILE"
sed -i'' -e 's/mint_denom": ".*"/mint_denom": "dym"/' "$GENESIS_FILE"

dymd keys add "$KEY_NAME" --keyring-backend test
dymd add-genesis-account "$(dymd keys show "$KEY_NAME" -a --keyring-backend test)" 100000000000dym
dymd gentx "$KEY_NAME" 100000000dym --chain-id "$CHAIN_ID" --keyring-backend test
dymd collect-gentxs
fi

# ...................................................... #
# ................... Run the chain .................... #
# ...................................................... #
# Run the dymension chain
dymd start
54 changes: 54 additions & 0 deletions scripts/setup_local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh

# Set parameters
DATA_DIRECTORY="$HOME/.dymension"
CONFIG_DIRECTORY="$DATA_DIRECTORY/config"
TENDERMINT_CONFIG_FILE="$CONFIG_DIRECTORY/config.toml"
CLIENT_CONFIG_FILE="$CONFIG_DIRECTORY/client.toml"
APP_CONFIG_FILE="$CONFIG_DIRECTORY/app.toml"
GENESIS_FILE="$CONFIG_DIRECTORY/genesis.json"
CHAIN_ID=${CHAIN_ID:-"local-testnet"}
MONIKER_NAME=${MONIKER_NAME:-"local"}
KEY_NAME=${KEY_NAME:-"local-user"}
SETTLEMENT_RPC=${SETTLEMENT_RPC:-"0.0.0.0:26657"}
P2P_ADDRESS=${P2P_ADDRESS:-"0.0.0.0:26656"}

# Validate dymension binary exists
export PATH=$PATH:$HOME/go/bin
if ! command -v dymd; then
make install

if ! command -v dymd; then
echo "dYmension binary not found in $PATH"
exit 1
fi
fi

# Verify that a genesis file doesn't exists for the dymension chain
if [ -f "$GENESIS_FILE" ]; then
printf "\n======================================================================================================"
echo "A genesis file already exists. building the chain will delete all previous chain data. continue? (y/n)"
read -r answer
if [ "$answer" != "${answer#[Yy]}" ]; then
rm -rf "$DATA_DIRECTORY"
else
exit 1
fi
fi

# Create and init dymension chain
dymd init "$MONIKER_NAME" --chain-id="$CHAIN_ID"
dymd tendermint unsafe-reset-all

sed -i'' -e "/\[rpc\]/,+3 s/laddr *= .*/laddr = \"tcp:\/\/$SETTLEMENT_RPC\"/" "$TENDERMINT_CONFIG_FILE"
sed -i'' -e "/\[p2p\]/,+3 s/laddr *= .*/laddr = \"tcp:\/\/$P2P_ADDRESS\"/" "$TENDERMINT_CONFIG_FILE"
sed -i'' -e "s/^chain-id *= .*/chain-id = \"$CHAIN_ID\"/" "$CLIENT_CONFIG_FILE"
sed -i'' -e "s/^node *= .*/node = \"tcp:\/\/$SETTLEMENT_RPC\"/" "$CLIENT_CONFIG_FILE"
sed -i'' -e 's/^enable *= true/enable = false/' "$APP_CONFIG_FILE"
sed -i'' -e 's/bond_denom": ".*"/bond_denom": "dym"/' "$GENESIS_FILE"
sed -i'' -e 's/mint_denom": ".*"/mint_denom": "dym"/' "$GENESIS_FILE"

dymd keys add "$KEY_NAME" --keyring-backend test
dymd add-genesis-account "$(dymd keys show "$KEY_NAME" -a --keyring-backend test)" 100000000000dym
dymd gentx "$KEY_NAME" 100000000dym --chain-id "$CHAIN_ID" --keyring-backend test
dymd collect-gentxs
11 changes: 11 additions & 0 deletions x/rollapp/keeper/msg_server_update_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"strconv"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
Expand Down Expand Up @@ -131,5 +132,15 @@ func (k msgServer) UpdateState(goCtx context.Context, msg *types.MsgUpdateState)
FinalizationQueue: newFinalizationQueue,
})

ctx.EventManager().EmitEvent(
sdk.NewEvent(types.EventTypeStateUpdate,
sdk.NewAttribute(types.AttributeKeyRollappId, msg.RollappId),
sdk.NewAttribute(types.AttributeKeyStateInfoIndex, strconv.FormatUint(stateInfoIndex.Index, 10)),
sdk.NewAttribute(types.AttributeKeyStartHeight, strconv.FormatUint(msg.StartHeight, 10)),
sdk.NewAttribute(types.AttributeKeyNumBlocks, strconv.FormatUint(msg.NumBlocks, 10)),
sdk.NewAttribute(types.AttributeKeyDAPath, msg.DAPath),
),
)

return &types.MsgUpdateStateResponse{}, nil
}
11 changes: 11 additions & 0 deletions x/rollapp/types/events.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package types

const (
EventTypeStateUpdate = "state_update"

AttributeKeyRollappId = "rollapp_id"
AttributeKeyStateInfoIndex = "state_info_index"
AttributeKeyStartHeight = "start_height"
AttributeKeyNumBlocks = "num_blocks"
AttributeKeyDAPath = "da_path"
)