-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat(SPV-1535) handle ARC callback #935
base: main
Are you sure you want to change the base?
Conversation
Manual TestsβΉοΈ Remember to ask team members to perform manual tests and to assign |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #935 +/- ##
==========================================
- Coverage 35.63% 35.30% -0.33%
==========================================
Files 424 427 +3
Lines 20035 20236 +201
==========================================
+ Hits 7139 7145 +6
- Misses 12299 12494 +195
Partials 597 597
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
}, | ||
"On SentToNetwork do nothing": { | ||
txInfo: minimalTxInfo(chainmodels.SentToNetwork), | ||
expectStatus: "BROADCASTED", |
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.
Minor suggestion: Would it make sense to group these statuses into constants rather than writing them directly?
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.
Actually, there is such type already defined - I'll adjust this :)
Model(&database.TrackedTransaction{}). | ||
WithContext(ctx). | ||
Where("id = ?", txID). | ||
Update("tx_status", status).Error |
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.
As I understand it, at this stage of development we are not considering implementing concurrency control mechanisms to avoid stale data? π€
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.
Don't understand - could you explain what you're thinking about?
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 think that he is saying that you can override tx_status that was already set by different process/routine
const bearerSchema = "Bearer " | ||
|
||
// RegisterCallback registers the ARC callback handler and sets up final URL sent to ARC during broadcast. | ||
func (s *Service) RegisterCallback(handler chainmodels.TXInfoHandler, router *gin.Engine) { |
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.
Hmmm... imho it should be done in a standard way (like the one for swagger v2)
It's counter intuitive to search for that thing in arc service
hostURL, err := url.Parse(s.arcCfg.Callback.URL) | ||
if err != nil { | ||
panic(spverrors.Wrapf(err, "failed to parse ARC callback URL: %s", s.arcCfg.Callback.URL)) | ||
} | ||
|
||
hostURL.Path = callbackPath | ||
s.arcCfg.Callback.URL = hostURL.String() |
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.
maybe Callback config could have a method for getting callback path and full callback url
if err != nil { | ||
return spverrors.Wrapf(err, "failed to parse merkle path for transaction %s", txInfo.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.
consider adding a check for merklepath (or maybe it will be checked during creation of BEEF hex - worth checking):
_, err = bump.ComputeRootHex(lo.ToPtr(txInfo.TxID)) | |
if err != nil { | |
return spverrors.Wrapf(err, "failed to validate merkle path %s for transaction %s", txInfo.MerklePath, txInfo.TxID) | |
} | |
This will prevent updating merkle path to some invalid value.
Or maybe if error occurs we should store info about this π€
The only problem here is that, it is taking some time to calculate this root - but actually we're doing the same for each and every beef
return spverrors.Wrapf(err, "failed to get BEEF hex for transaction %s", txInfo.TxID) | ||
} | ||
|
||
err = s.transactionsRepo.SetAsMined(ctx, txInfo.TxID, txInfo.BlockHash, txInfo.BlockHeight, beefHex) |
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.
Sorry but I don't like this approach, because it is forceing us to move a lot of logic into database layer, which doens't allow to test anything without running the integration tests.
I would suggest to:
- get domain transaction from repository
- check if last update is older then TxInfo timestamp
- if not then omit
- call set problematic if it's problematic
- call
tx.Mined(blockhash, merklepath)
- in set merkle path it should mark it as mined
- set block height from merklepath
- set block hash from block hash
- build beef with merkle path
- remove raw tx
- save tx
"block_height": blockHeight, | ||
"tx_status": txmodels.TxStatusMined, | ||
"beef_hex": beefHex, | ||
}).Error |
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 clear also connection with SourceTxInputs because those entries are not needed anymore.
|
||
// when: | ||
test.txInfo.TxID = receiveTxID | ||
when.ARC().ReceivesCallback(test.txInfo) |
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.
It should be rather π :
when.ARC().ReceivesCallback(test.txInfo) | |
when.ARC().SendsCallback(test.txInfo) |
WithTxID(receiveTxID). | ||
WithTxStatus(test.expectStatus) | ||
|
||
// TODO: Assert for tx block height/hash and BEEF after Searching Transactions is implemented |
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.
Maybe we should actually add those information to operations endpoint - because it seems like a common thing that we display in wallets (and use for whatsonchain links)
t.Run(name, func(t *testing.T) { | ||
// given: | ||
given, when, then := testabilities.New(t) | ||
cleanup := given.StartedSPVWalletV2(testengine.WithARCCallback("https://example.com", testabilities.ARCCallbackToken)) |
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.
Why don't we make those configs default?
@@ -0,0 +1,101 @@ | |||
package integrationtests |
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.
Why is it in integrations tests?
It should be rather test next to the http handler,
You probably could use a Faucet().TopUp() then and make a different ARC callbacks for different statuses.
|
||
type arcActions struct { | ||
t testing.TB | ||
fixture *fixture |
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.
you have access to SPVWalletApplicationFixture,
maybe it could return config, and you could take auth token from config π€
Pull Request Checklist