-
Notifications
You must be signed in to change notification settings - Fork 131
Add chain_anchor with block_timestamp to AssetLeaves RPC #1480
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
base: main
Are you sure you want to change the base?
Conversation
rpcserver.go
Outdated
// Ensure block timestamp is set for on-chain assets. | ||
if rpcAsset.ChainAnchor != nil && | ||
rpcAsset.ChainAnchor.BlockHeight != 0 && | ||
rpcAsset.ChainAnchor.BlockTimestamp == 0 { | ||
|
||
ts := r.cfg.ChainBridge.GetBlockTimestamp( | ||
ctx, | ||
rpcAsset.ChainAnchor.BlockHeight, | ||
) | ||
rpcAsset.ChainAnchor.BlockTimestamp = ts | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This block doesn't feel quite right here, but I added it because I saw that the block_timestamp
field was 0
when running tapcli assets list
. I didn't see how to grab the timestamp from within the assets store dbAssetsToChainAssets function since it isn't stored in the DB. I didn't feel like it would be appropriate to somehow call ChainBridge.GetBlockTimestamp()
from the db level. Please let me know if there's a better way to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see how to grab the timestamp from within the assets store dbAssetsToChainAssets function since it isn't stored in the D
Yeah the timestamp isn't stored in the DB, as we only store the transaction and not also the header.
However the header is stored in the proof.Proof
struct, which is a state transition proof (new txn properly followed all the rules). Looks like you start to decode the proof below here in the diff, so you should be able to get the header, then the timestamp from that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 243 to 246 in db28a03
// BlockHeader is the current block header committing to the on-chain | |
// transaction attempting an asset state transition. | |
BlockHeader wire.BlockHeader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I was able to fetch the proof and grab the timestamp from the block header. Thanks for the pointer. This implementation feels much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eww! Looks like this change broke some of the tests. Going to try to resolve those issues.
Pull Request Test Coverage Report for Build 14645961836Details
💛 - Coveralls |
50e0937
to
55496e8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very useful feature. See inline comment for a bit more light-weight approach suggestion that should also fix the tests.
7b6367e
to
5130af8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, LGTM 🎉
This adds a new `AnchorBlockTimestamp` field to the `ChainAsset` struct which gets set to the timestamp of the block header encoded in the `Proof`.
Add a `block_timestamp` field to the `AnchorInfo` RPC message which will contain the Unix timestamp of the block containing the anchor transaction
When marshalling a chain asset, ensure the block timestamp is set. This is needed for assets fetched from the DB since the timestamp is not stored in the table with the asset.
5130af8
to
ba859b9
Compare
Closes #1477
We would like to update Terminal to display all of the asset mints/burns for a group key. We also want to display the txid and timestamp of the mint txn. I'm using the universe
AssetLeaves
RPC to get the list of issued assets. This is when I realized that thechain_anchor
field was not being set in this response.I have taken a stab at implementing the fix to include the
chain_anchor
field in theAssetLeaves
RPC response. I updatedmarshalAssetLeaf
to callMarshalChainAsset
which includes the chain anchor info. I also added a newblock_timestamp
field to the RPC message, which gets set from the block header which is encoded in the proof.Note: This is my first contribution to this repo and would appreciate any guidance on whether the approach I've taken here is good. There may be better ways to get the desired result which I have not discovered yet.