fix: provider side deposit cache#767
Conversation
fcef96d to
08111cb
Compare
chrmatt
left a comment
There was a problem hiding this comment.
I don't quite understand the logic. Maybe worth commenting somehow how this works. What I think I understand: When a provider commits to a bid, a pending refund for the bid amount is created, linked to the commitment digest. When some commitments get opened, commitments not matching the block winner get their refund applied. When an opened commitment is stored, the refund gets dropped.
What I don't understand: Why are the two cases handled in different functions (open vs store opened)? It seems opening (some?) commitment is required to trigger checking (all?) commitments for different block winners. What if another provider won and doesn't open anything (e.g., because they haven't committed). Will the refunds still be applied? Why not do these checks (both apply and drop) when a winner is announced?
Note that these will interfere with the issue we discussed in some call recently: Winners are announced directly, but oracle waits 10 blocks to be reorg resilient. If reorg happens, "wrong" winner will be announced and also the refund logic here will be applied incorrectly.
08111cb to
4fd6041
Compare
This sounds correct. Specifically, every commitment from a provider gets a pendingRefund stored, where the amount is the bid amount. Every pending refund should (eventually) either get applied or dropped. Every commitment (relevant to the provider running the node) gets seen by the In the alternative case that An event landing on-chain is the first definitive signal that one's own provider has won, and the refund can be dropped, so that's why it's applied there. If That being said, I don't see an issue with having the drop/apply logic both happen within Yes this issue is related to the winner announcement/reorg issue we discussed previously. |
But the |
No, |
Oh, I see. Then it should be all good! |
| p.logger.Error("failed to parse bid amount", "bidAmount", bid.BidAmount) | ||
| return status.Errorf(codes.Internal, "failed to parse bid amount: %v", bid.BidAmount) | ||
| } | ||
| p.depositMgr.AddPendingRefund(commitmentDigest, *bidderAddr, providerAddr, bidAmount) |
There was a problem hiding this comment.
This entire refund logic should be handled by tracker. There is no point adding this additional dependency to the preconfirmation protocol directly. The tracker can add the pending refund during the TrackCommitment call itself.
Also how do we handle refunds related to decayed amount? I think we should handle the refunds during the FundsUnlocked and FundsRetrieved events as well. We should refund the decayed amount.
There was a problem hiding this comment.
Re first point, sound good. Re second point, see first paragraph of #746 (comment)
| } | ||
|
|
||
| func (dm *DepositManager) CheckAndDeductDeposit( | ||
| func (dm *DepositManager) CheckDeposit( |
There was a problem hiding this comment.
Per request, deduction no longer happens here and now happens in tracker.go
There was a problem hiding this comment.
Again this looked like a good idea but now I think about it, there is scope for double spending if we dont deduct immediately.
Also, I would prefer the tracker logic to be independent of this deposit manager. The tracker runs for both bidders and providers, so having this provider specific logic is not looking right. Strictly from a design perspective.
What I would propose is that we keep this CheckAndDeduct functionality as is. Also the Refund on error part as is. What we can do is pass in the Notifications implementation to DepositManager and subscribe to notifications from the tracker. The tracker already emits CommitmentFailed event which can be used to refund in deposit manager code itself.
We can create a new event which is fired while openingCommitments that we can look at in DepositManager to refund for the case of not winning.
This way the deposit manager functionality is independent of the tracker.
cdfdaed to
d6c51d9
Compare
| } | ||
|
|
||
| func (dm *DepositManager) CheckAndDeductDeposit( | ||
| func (dm *DepositManager) CheckDeposit( |
There was a problem hiding this comment.
Again this looked like a good idea but now I think about it, there is scope for double spending if we dont deduct immediately.
Also, I would prefer the tracker logic to be independent of this deposit manager. The tracker runs for both bidders and providers, so having this provider specific logic is not looking right. Strictly from a design perspective.
What I would propose is that we keep this CheckAndDeduct functionality as is. Also the Refund on error part as is. What we can do is pass in the Notifications implementation to DepositManager and subscribe to notifications from the tracker. The tracker already emits CommitmentFailed event which can be used to refund in deposit manager code itself.
We can create a new event which is fired while openingCommitments that we can look at in DepositManager to refund for the case of not winning.
This way the deposit manager functionality is independent of the tracker.
3fa72cf to
a4b8893
Compare
a4b8893 to
1b5c3ff
Compare
aloknerurkar
left a comment
There was a problem hiding this comment.
I am approving it. Have some minor comments, so you can address them and merge.
PR into #746 addressing #746 (comment)