-
Notifications
You must be signed in to change notification settings - Fork 111
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
Add ListBurns
RPC
#1178
base: main
Are you sure you want to change the base?
Add ListBurns
RPC
#1178
Conversation
5c69a1e
to
8037aff
Compare
Pull Request Test Coverage Report for Build 11816308677Details
💛 - Coveralls |
8037aff
to
dcb3eee
Compare
dcb3eee
to
a1ddf99
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.
Looks pretty good. I wonder if we should add a Golang based "migration" of sort that queries existing assets in the DB, checks if they're burns (cannot be done on SQL level alone) and then inserts them into the new table retroactively?
Perhaps we could add a mechanism that detects if any DB level migrations were executed. And if they were, we can assume an update happened and could run these Golang-level checks (which would need to be idempotent).
a1ddf99
to
0055981
Compare
0055981
to
7f7febe
Compare
7f7febe
to
ba5db4b
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.
Super close!
var writeTxOpts AssetStoreTxOptions | ||
return a.db.ExecTx(ctx, &writeTxOpts, func(q ActiveAssetsStore) error { | ||
// Look up the transfer that relates to this txid. | ||
// TODO(george): We assume there's a single burn in every txn, |
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 don't think we need this TODO. If there are multiple burns in a transaction, we'd call InsertBurn
multiple times with the same txid
. But because they would all still be in the same transfer, we'd query the same transfer ID which is correct.
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.
^ makes sense
return fmt.Errorf("unable to query asset transfers: %w", | ||
err) | ||
} | ||
assetTransfer := assetTransfers[0] |
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.
Should check that we have exactly one result (which should always be the case when we query with an anchor TX hash).
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.
Yeah otherwise, we'll panic here.
abt.asset_id, | ||
abt.group_key, | ||
abt.amount, | ||
ct.txid AS anchor_txid -- Retrieving the txid from chain_txns |
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.
nit: missing full stop, here and below.
abt.amount, | ||
ct.txid AS anchor_txid -- Retrieving the txid from chain_txns | ||
FROM asset_burn_transfers abt | ||
JOIN asset_transfers at ON abt.transfer_id = at.id |
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.
Looks like we don't need to join on asset_transfers
? Since we don't seem to be using at
anywhere.
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.
Perhaps the idea was to return the full transfer information alongside the burn?
From the PoV of a future query CLI, I think that would be desirable.
// Let's insert a burn. | ||
assetID := inputAsset.ID() | ||
transferID := assetTransfers[0].ID | ||
_, err = assetsStore.db.InsertBurn(ctx, sqlc.InsertBurnParams{ |
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.
We'll want to test the actual AssetStore
's QueryBurns
and InsertBurn
methods, not directly call into the DB-level methods.
in *taprpc.ListBurnsRequest) (*taprpc.ListBurnsResponse, error) { | ||
|
||
burns, err := r.cfg.AssetStore.QueryBurns( | ||
ctx, sqlc.QueryBurnsParams{ |
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.
We should use the alias tapdb.QueryBurnsFilters
here.
anchorTxidStr := ctx.String(anchorTxidName) | ||
anchorTxid, err := hex.DecodeString(anchorTxidStr) | ||
if err != nil { | ||
return fmt.Errorf("invalid anchor txid") |
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.
nit: missing wrapped error.
var writeTxOpts AssetStoreTxOptions | ||
return a.db.ExecTx(ctx, &writeTxOpts, func(q ActiveAssetsStore) error { | ||
// Look up the transfer that relates to this txid. | ||
// TODO(george): We assume there's a single burn in every txn, |
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.
^ makes sense
return fmt.Errorf("unable to query asset transfers: %w", | ||
err) | ||
} | ||
assetTransfer := assetTransfers[0] |
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.
Yeah otherwise, we'll panic here.
|
||
return nil | ||
}) | ||
|
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.
Style nit: extra space.
@@ -2204,6 +2205,44 @@ func TestTransferOutputProofDeliveryStatus(t *testing.T) { | |||
require.Equal( | |||
t, randBlockHash[:], assetTransfers[0].AnchorTxBlockHash, | |||
) | |||
|
|||
// Let's insert a burn. |
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.
How about we make another isolated unit test for this? This exiting test is already rather long/large.
abt.amount, | ||
ct.txid AS anchor_txid -- Retrieving the txid from chain_txns | ||
FROM asset_burn_transfers abt | ||
JOIN asset_transfers at ON abt.transfer_id = at.id |
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.
Perhaps the idea was to return the full transfer information alongside the burn?
From the PoV of a future query CLI, I think that would be desirable.
@@ -3312,12 +3314,56 @@ func (r *rpcServer) BurnAsset(ctx context.Context, | |||
} | |||
} | |||
|
|||
// At this point everything completed correctly, so we log this burn in |
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.
Hmm, perhaps we should do this further in the pipeline? So in the same db transaction that we insert the transfer.
Otherwise, if we crash here, then the burn is never inserted in the db, and we exit in an inconsistent state.
rpcBurns := fn.Map(burns, marshalRpcBurn) | ||
|
||
return &taprpc.ListBurnsResponse{ | ||
Burns: rpcBurns, |
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.
Re other comment, I think it would be useful to include the full transfer here, also maybe the raw tx itself?
Description
We're currently able to provably burn assets with tapd but we have no (easy) way of retrieving burn related historical data. This PR adds a DB table and exposes some new RPC methods/parameters to help keep track of burns.
When completing an asset burn, we add an entry to the new burns table. We also add a new
ListBurns
method which returns a list of all burns that pass the user-provided filters (asset id, group id, anchor txid)Closes #1095