在Hyperledger Fabric中提交(或完成)事务时如何获取时间戳 [英] How to get timestamp when transaction is committed (or completed) in Hyperledger Fabric

查看:467
本文介绍了在Hyperledger Fabric中提交(或完成)事务时如何获取时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要计算提交事务时的时间戳"和提交事务时的时间戳"之间的差.是否可以在结构中获取已提交(或已完成)的tx时间戳?

I need to calculate the difference between "the timestamp when transaction is submitted" and "the timestamp when transaction is committed". Is it possible to get the tx committed (or completed) timestamp in fabric?

我试图使用在我的作曲家频道上运行的Hyperledger Explorer.我可以在块内看到tx时间戳.但是我不确定这是创建时间戳还是提交时间戳.另外,我可以将资源管理器时间戳转换为ISO 8601格式吗?

I tried to use Hyperledger Explorer running on my composer channel. I can see tx timestamp inside the block. But I am not sure whether it is creation or committing timestamp. Also, can I convert explorer timestamp to ISO 8601 format?

请帮助我.

推荐答案

您看到的时间戳是认可时间时间戳,您可以使用以下API在链码调用过程中对其进行访问:

The timestamp you see is the endorsement time timestamp, you can get access to it during chaincode invocation by using following API:

// GetTxTimestamp returns the timestamp when the transaction was created. This
// is taken from the transaction ChannelHeader, therefore it will indicate the
// client's timestamp, and will have the same value across all endorsers.
GetTxTimestamp() (*timestamp.Timestamp, error)

如果您想计算两个事件之间的差异,我建议利用事件中心来获得有关已提交事务的直接通知.基本上,您需要订阅等待事务的事件,然后您便可以计算出差异,请注意,您需要计算平均请求RTT,以从最终结果中扣除该差额,以获得更准确的评估.要查看如何订阅事件,可以在此处查看示例

If you would like to compute the difference between two events, I'd suggest to leverage events hub to get direct notification of transaction being committed. You basically need to subscribe to events waiting for your transaction then you will be able to compute the difference, note you need to compute average request RTT to deduct it from the final result to get more accurate evaluation. To see how you can get subscribed to events you can see an example here (Deprecated)block_listener.go.

这篇关于在Hyperledger Fabric中提交(或完成)事务时如何获取时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆