Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jamaljsr
Copy link
Member

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 the chain_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 the AssetLeaves RPC response. I updated marshalAssetLeaf to call MarshalChainAsset which includes the chain anchor info. I also added a new block_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.

rpcserver.go Outdated
Comment on lines 1173 to 1220
// 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
}
Copy link
Member Author

@jamaljsr jamaljsr Apr 19, 2025

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.

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// BlockHeader is the current block header committing to the on-chain
// transaction attempting an asset state transition.
BlockHeader wire.BlockHeader

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.

Copy link
Member Author

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.

@coveralls
Copy link

coveralls commented Apr 19, 2025

Pull Request Test Coverage Report for Build 14645961836

Details

  • 0 of 23 (0.0%) changed or added relevant lines in 4 files are covered.
  • 41 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.02%) to 28.678%

Changes Missing Coverage Covered Lines Changed/Added Lines %
proof/proof.go 0 1 0.0%
taprpc/marshal.go 0 1 0.0%
taprpc/taprootassets.pb.go 0 5 0.0%
rpcserver.go 0 16 0.0%
Files with Coverage Reduction New Missed Lines %
asset/group_key.go 2 57.89%
commitment/tap.go 2 72.05%
tappsbt/create.go 2 26.74%
tapdb/multiverse.go 6 53.03%
asset/mock.go 7 64.71%
asset/asset.go 22 47.97%
Totals Coverage Status
Change from base Build 14638699557: -0.02%
Covered Lines: 26697
Relevant Lines: 93091

💛 - Coveralls

@jamaljsr jamaljsr force-pushed the leaves-chain-anchor branch 3 times, most recently from 50e0937 to 55496e8 Compare April 22, 2025 05:06
Copy link
Member

@guggero guggero left a 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.

@jamaljsr jamaljsr force-pushed the leaves-chain-anchor branch 2 times, most recently from 7b6367e to 5130af8 Compare April 22, 2025 13:03
@jamaljsr jamaljsr requested a review from guggero April 23, 2025 01:10
Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, LGTM 🎉

@levmi levmi requested a review from ffranr April 24, 2025 14:40
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.
@jamaljsr jamaljsr force-pushed the leaves-chain-anchor branch from 5130af8 to ba859b9 Compare April 24, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] ChainAnchor field missing in AssetLeaves RPC response
4 participants