diff --git a/flusher/flusher/db.py b/flusher/flusher/db.py index 868215898..6cbf45ef7 100644 --- a/flusher/flusher/db.py +++ b/flusher/flusher/db.py @@ -460,4 +460,5 @@ def Column(*args, **kwargs): Column("counterparty_channel", sa.String), Column("state", sa.Integer), Column("order", sa.String), + Column("last_update", CustomDateTime, index=True), ) diff --git a/flusher/flusher/handler.py b/flusher/flusher/handler.py index c5bff6aaa..d41ca19ab 100644 --- a/flusher/flusher/handler.py +++ b/flusher/flusher/handler.py @@ -392,6 +392,9 @@ def handle_set_request_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"] + msg["tx_id"] = self.get_transaction_id(msg["hash"]) del msg["hash"] self.conn.execute( @@ -399,13 +402,20 @@ def handle_new_incoming_packet(self, msg): ) def handle_new_outgoing_packet(self, msg): + 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"]) del msg["hash"] + self.conn.execute( insert(outgoing_packets).values(**msg).on_conflict_do_nothing(constraint="outgoing_packets_pkey") ) def handle_update_outgoing_packet(self, msg): + self.update_last_update_channel(msg['src_port'], msg['src_channel'], msg['block_time']) + del msg["block_time"] + condition = True for col in outgoing_packets.primary_key.columns.values(): condition = (col == msg[col.name]) & condition @@ -439,3 +449,10 @@ def handle_set_connection(self, msg): def handle_set_channel(self, msg): self.conn.execute(insert(channels).values(**msg).on_conflict_do_update(constraint="channels_pkey", set_=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 + ) + ) diff --git a/hooks/emitter/channel.go b/hooks/emitter/channel.go index 0b41b6b94..0bef25ac3 100644 --- a/hooks/emitter/channel.go +++ b/hooks/emitter/channel.go @@ -25,6 +25,7 @@ func (h *Hook) emitSetChannel(ctx sdk.Context, portId string, channelId string) "counterparty_channel": channel.Counterparty.ChannelId, "state": channel.State, "order": channel.Ordering, + "last_update": ctx.BlockTime().UnixNano(), }) } @@ -109,6 +110,7 @@ func newPacket( ) common.JsDict { return common.JsDict{ "block_height": ctx.BlockHeight(), + "block_time": ctx.BlockTime().UnixNano(), "src_channel": srcChannel, "src_port": srcPort, "sequence": sequence,