Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerKSI committed Oct 9, 2023
2 parents 560578a + 0350bf7 commit 75c6d7f
Show file tree
Hide file tree
Showing 15 changed files with 405 additions and 72 deletions.
4 changes: 3 additions & 1 deletion app/upgrades/v2_6/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
"github.com/cosmos/cosmos-sdk/x/authz"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
"github.com/cosmos/cosmos-sdk/x/feegrant"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand All @@ -24,7 +26,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: storetypes.StoreUpgrades{
Added: []string{group.StoreKey, globalfeetypes.StoreKey},
Added: []string{group.StoreKey, globalfeetypes.StoreKey, consensusparamtypes.StoreKey, crisistypes.StoreKey},
},
}

Expand Down
50 changes: 50 additions & 0 deletions app/upgrades/v2_6/upgrades.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
package v2_6

import (
oracletypes "github.com/bandprotocol/chain/v2/x/oracle/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icahosttypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types"

"github.com/bandprotocol/chain/v2/app/keepers"
"github.com/bandprotocol/chain/v2/app/upgrades"
Expand All @@ -18,6 +30,44 @@ func CreateUpgradeHandler(
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// Set param key table for params module migration
for _, subspace := range keepers.ParamsKeeper.GetSubspaces() {
subspace := subspace

var keyTable paramstypes.KeyTable
switch subspace.Name() {
case authtypes.ModuleName:
keyTable = authtypes.ParamKeyTable() //nolint:staticcheck
case banktypes.ModuleName:
keyTable = banktypes.ParamKeyTable() //nolint:staticcheck
case stakingtypes.ModuleName:
keyTable = stakingtypes.ParamKeyTable() //nolint:staticcheck
case minttypes.ModuleName:
keyTable = minttypes.ParamKeyTable() //nolint:staticcheck
case distrtypes.ModuleName:
keyTable = distrtypes.ParamKeyTable() //nolint:staticcheck
case slashingtypes.ModuleName:
keyTable = slashingtypes.ParamKeyTable() //nolint:staticcheck
case govtypes.ModuleName:
keyTable = govv1.ParamKeyTable() //nolint:staticcheck
case crisistypes.ModuleName:
keyTable = crisistypes.ParamKeyTable() //nolint:staticcheck
// ibc types
case ibctransfertypes.ModuleName:
keyTable = ibctransfertypes.ParamKeyTable() //nolint:staticcheck
case icahosttypes.SubModuleName:
keyTable = icahosttypes.ParamKeyTable() //nolint:staticcheck
case oracletypes.ModuleName:
keyTable = oracletypes.ParamKeyTable() //nolint:staticcheck
default:
continue
}

if !subspace.HasKeyTable() {
subspace.WithKeyTable(keyTable)
}
}

hostParams := icahosttypes.Params{
HostEnabled: true,
// specifying the whole list instead of adding and removing. Less fragile.
Expand Down
1 change: 1 addition & 0 deletions cmd/faucet/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func handleRequest(gc *gin.Context, c *Context) {

clientCtx := client.Context{
Client: c.client,
Codec: cdc,
TxConfig: band.MakeEncodingConfig().TxConfig,
BroadcastMode: "async",
InterfaceRegistry: band.MakeEncodingConfig().InterfaceRegistry,
Expand Down
12 changes: 12 additions & 0 deletions flusher/flusher/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,3 +555,15 @@ def Column(*args, **kwargs):
Column("metadata", sa.String),
Column("submit_time", CustomDateTime),
)

relayer_tx_stat_days = sa.Table(
"relayer_tx_stat_days",
metadata,
Column("date", CustomDate, primary_key=True),
Column("port", sa.String, primary_key=True),
Column("channel", sa.String, primary_key=True),
Column("address", sa.String, primary_key=True),
Column("ibc_received_txs", sa.Integer),
Column("last_update_at", CustomDateTime),
sa.ForeignKeyConstraint(["port", "channel"], ["channels.port", "channels.channel"]),
)
61 changes: 54 additions & 7 deletions flusher/flusher/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
group_policies,
group_proposals,
group_votes,
relayer_tx_stat_days,
)


Expand All @@ -53,6 +54,9 @@ def __init__(self, conn):
def get_transaction_id(self, tx_hash):
return self.conn.execute(select([transactions.c.id]).where(transactions.c.hash == tx_hash)).scalar()

def get_transaction_sender(self, id):
return self.conn.execute(select([transactions.c.sender]).where(transactions.c.id == id)).scalar()

def get_validator_id(self, val):
return self.conn.execute(select([validators.c.id]).where(validators.c.operator_address == val)).scalar()

Expand Down Expand Up @@ -89,6 +93,14 @@ def get_oracle_script_id(self, id):
def get_group_id_from_policy_address(self, address):
return self.conn.execute(select([group_policies.c.group_id]).where(group_policies.c.address == address)).scalar()

def get_ibc_received_txs(self, date, port, channel, address):
msg = {"date": date, "port": port, "channel": channel, "address": address}
condition = True
for col in relayer_tx_stat_days.primary_key.columns.values():
condition = (col == msg[col.name]) & condition

return self.conn.execute(select([relayer_tx_stat_days.c.ibc_received_txs]).where(condition)).scalar()

def handle_new_block(self, msg):
self.conn.execute(blocks.insert(), msg)

Expand Down Expand Up @@ -483,17 +495,22 @@ def handle_update_data_source_requests_count_per_day(self, msg):
)

def handle_new_incoming_packet(self, msg):
self.update_last_update_channel(msg['dst_port'], msg['dst_channel'], msg['block_time'])
del msg["block_time"]
self.update_last_update_channel(msg["dst_port"], msg["dst_channel"], msg["block_time"])

msg["tx_id"] = self.get_transaction_id(msg["hash"])
del msg["hash"]

msg["sender"] = self.get_transaction_sender(msg["tx_id"])
self.handle_set_relayer_tx_stat_days(msg["dst_port"], msg["dst_channel"], msg["block_time"], msg["sender"])
del msg["block_time"]
del msg["sender"]

self.conn.execute(
insert(incoming_packets).values(**msg).on_conflict_do_nothing(constraint="incoming_packets_pkey")
)

def handle_new_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
self.update_last_update_channel(msg["src_port"], msg["src_channel"], msg["block_time"])
del msg["block_time"]

msg["tx_id"] = self.get_transaction_id(msg["hash"])
Expand All @@ -504,7 +521,7 @@ def handle_new_outgoing_packet(self, msg):
)

def handle_update_outgoing_packet(self, msg):
self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time'])
self.update_last_update_channel(msg["src_port"], msg["src_channel"], msg["block_time"])
del msg["block_time"]

condition = True
Expand Down Expand Up @@ -557,7 +574,37 @@ def handle_set_channel(self, msg):

def update_last_update_channel(self, port, channel, timestamp):
self.conn.execute(
channels.update().where((channels.c.port == port) & (channels.c.channel == channel)).values(
last_update=timestamp
)
channels.update()
.where((channels.c.port == port) & (channels.c.channel == channel))
.values(last_update=timestamp)
)

def handle_set_relayer_tx_stat_days(self, port, channel, timestamp, address):
relayer_tx_stat_day = {
"date": timestamp,
"port": port,
"channel": channel,
"address": address,
"last_update_at": timestamp,
}

if (
self.get_ibc_received_txs(
relayer_tx_stat_day["date"],
relayer_tx_stat_day["port"],
relayer_tx_stat_day["channel"],
relayer_tx_stat_day["address"],
)
is None
):
relayer_tx_stat_day["ibc_received_txs"] = 1
self.conn.execute(relayer_tx_stat_days.insert(), relayer_tx_stat_day)
else:
condition = True
for col in relayer_tx_stat_days.primary_key.columns.values():
condition = (col == relayer_tx_stat_day[col.name]) & condition
self.conn.execute(
relayer_tx_stat_days.update()
.where(condition)
.values(ibc_received_txs=relayer_tx_stat_days.c.ibc_received_txs + 1, last_update_at=timestamp)
)
24 changes: 24 additions & 0 deletions hasura/hasura-metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@
remote_table:
name: outgoing_packets
schema: public
- name: relayer_tx_stat_days
using:
manual_configuration:
column_mapping:
channel: channel
port: port
insertion_order: null
remote_table:
name: relayer_tx_stat_days
schema: public
- table:
name: connections
schema: public
Expand Down Expand Up @@ -615,6 +625,20 @@
- name: oracle_script
using:
foreign_key_constraint_on: oracle_script_id
- table:
name: relayer_tx_stat_days
schema: public
object_relationships:
- name: channel_by_channel_port
using:
manual_configuration:
column_mapping:
channel: channel
port: port
insertion_order: null
remote_table:
name: channels
schema: public
- table:
name: reporters
schema: public
Expand Down
52 changes: 37 additions & 15 deletions hooks/emitter/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,21 +226,43 @@ func (h *Hook) AfterInitChain(ctx sdk.Context, req abci.RequestInitChain, res ab
h.cdc.MustUnmarshalJSON(genesisState[govtypes.ModuleName], &govState)
for _, proposal := range govState.Proposals {
msgs, _ := proposal.GetMsgs()
content := msgs[0].(*govv1.MsgExecLegacyContent).Content.GetCachedValue().(govv1beta1.Content)
h.Write("NEW_PROPOSAL", common.JsDict{
"id": proposal.Id,
"proposer": nil,
"type": content.ProposalType(),
"title": content.GetTitle(),
"description": content.GetDescription(),
"proposal_route": content.ProposalRoute(),
"status": int(proposal.Status),
"submit_time": proposal.SubmitTime.UnixNano(),
"deposit_end_time": proposal.DepositEndTime.UnixNano(),
"total_deposit": sdk.NewCoins(proposal.TotalDeposit...).String(),
"voting_time": proposal.VotingStartTime.UnixNano(),
"voting_end_time": proposal.VotingEndTime.UnixNano(),
})
switch subMsg := msgs[0].(type) {
case *govv1.MsgExecLegacyContent:
content := subMsg.Content.GetCachedValue().(govv1beta1.Content)
h.Write("NEW_PROPOSAL", common.JsDict{
"id": proposal.Id,
"proposer": nil,
"type": content.ProposalType(),
"title": content.GetTitle(),
"description": content.GetDescription(),
"proposal_route": content.ProposalRoute(),
"status": int(proposal.Status),
"submit_time": common.TimeToNano(proposal.SubmitTime),
"deposit_end_time": common.TimeToNano(proposal.DepositEndTime),
"total_deposit": sdk.NewCoins(proposal.TotalDeposit...).String(),
"voting_time": common.TimeToNano(proposal.VotingStartTime),
"voting_end_time": common.TimeToNano(proposal.VotingEndTime),
"content": content,
})
case sdk.Msg:
h.Write("NEW_PROPOSAL", common.JsDict{
"id": proposal.Id,
"proposer": nil,
"type": sdk.MsgTypeURL(subMsg),
"title": proposal.Title,
"description": proposal.Summary,
"proposal_route": sdk.MsgTypeURL(subMsg),
"status": int(proposal.Status),
"submit_time": common.TimeToNano(proposal.SubmitTime),
"deposit_end_time": common.TimeToNano(proposal.DepositEndTime),
"total_deposit": sdk.NewCoins(proposal.TotalDeposit...).String(),
"voting_time": common.TimeToNano(proposal.VotingStartTime),
"voting_end_time": common.TimeToNano(proposal.VotingEndTime),
"content": subMsg,
})
default:
break
}
}
for _, deposit := range govState.Deposits {
h.Write("SET_DEPOSIT", common.JsDict{
Expand Down
Loading

0 comments on commit 75c6d7f

Please sign in to comment.