-
Notifications
You must be signed in to change notification settings - Fork 31
feat(core): optional shouldAddInputs
for Transaction.completeFee
#225
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(core): optional shouldAddInputs
for Transaction.completeFee
#225
Conversation
🦋 Changeset detectedLatest commit: 181c661 The changes in this PR will be included in the next version bump. This PR includes changesets to release 20 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
d429bd9
to
59afacc
Compare
The second commit addresses a prettier issue. We can review the first commit only. |
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.
Perfect, I wanted exactly to propose to move to this kind of specific errors for insufficient balance.
One note: would it make sense to also add the Coin name or symbol as in the error? (both message and property)
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 need a data source for name & symbol (SSRI/indexer), which will introduce extra cost and complexity, so I don't think it is worth it.
I suggest we can add the type
to the error property. As for the message, that will cause problems with compatibility and readability, so I prefer to keep it as it is.
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.
Updated to include the type
in Error properties.
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.
Reasonable! I also noticed that now the properties are required, nice!! 👍
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.
Perfect, in general I'd love to see more TypeDoc of this kind!! 👍 (Specific and descriptive)
With LLMs these TypeDoc are really easy to generate and often times they provide a lot of information to a new developer that otherwise would have to read thru the code itself instead of its documentation, so it could make sense to make it as best practice
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.
Agree. AI generates these docs and helps. We will add more docs in the future.
59afacc
to
3141935
Compare
let leastExtraCapacity = Zero; | ||
|
||
while (true) { | ||
const tx = this.clone(); |
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 is an issue right here: clone doesn't copy input metadata, so we are still re-fetching every single cell.
Let's say the current cell pool being examined is bigger that than the cache size, the cache will be thrashed and these requests will spill out to the underlying RPC. (Even worse if the Client doesn't have a cache)
While this is out of the scope of this FR, it could make sense to let the offline check operate on the original transaction, not on the clone.
What's your take on this @Hanssen0?
Also, in general, what's preventing us from cloning and prevent re-fetching in general by then shallowly copying the inputs?
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.
Thank you for noticing! This is a mistake. Once in a while, the clone
was implemented manually, and the cache in the CellInput
will be handled appropriately. Later, we change this to the default implementation from molecule,
which doesn't handle these extra fields.
I will fix 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.
it could make sense to let the offline check operate on the original transaction, not on the clone.
For this, because the change
function modifies the transaction, but we need to do this multiple times on the original transaction, we must clone the transaction to preserve the original version.
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.
Glad to hear!! Same as the core the the FR, this has been bothering me for a long time now, so much that I modified the behaviour of SmartTransaction.clone
to work around it! 🤣 (My solution was to shallowly copying inputs right in clone
, you may want to consider this behaviour)
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.
The new fix
commit should fix this problem. Please check.
The CellInput
is deep cloned to avoid any future problems. Although change
usually won't modify the inputs
, we have no idea what others may do with the cloned Transaction
.
3d1f59d
to
d993dd3
Compare
this.version, | ||
this.cellDeps.map((c) => c.clone()), | ||
this.headerDeps.map((h) => h), | ||
this.inputs.map((i) => i.clone()), |
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!! 👍
There is another smaller issue: In this regard, What's your take on this @Hanssen0? |
while (true) { | ||
const tx = this.clone(); | ||
const collected = await (async () => { | ||
if (!(options?.shouldAddInputs ?? true)) { |
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.
Smaller issue: why is this check inside the loop and not before the loop?
Inside the loop means it will be checked at every iteration, before the loop means that exactly one check happens for a single completeFee
call.
What's your take @Hanssen0?
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's because the leastFee
and leastExtraCapacity
change every iteration. If the change
function requests more capacity for the change cell, the check might fail.
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 are indeed 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.
I see no problems in the main change area, aka shouldAddInputs
option, from my point of view.
Normally, errors related to the Indeed, when I was designing this part, I chose vocalization to help identify the problem without adding too much work. I still think How do you think about adding another Error type for the change error? |
I would make it
|
Having a unified error could simplify error handling for the final dev. At any rate, you know best, so it's your call |
It sounds good. It's just a difficult decision for me to break the compatibility. I will follow this approach to simplify error handling and hope that no one will be affected by this (well, it should not be a big problem, right?). |
d993dd3
to
181c661
Compare
Fair point! I believe that if they are checking the error based on prefix, by using the more general prefix, the error will be still ok. An alternative is to use a totally different message in case of change cell for being back-ward compatible 🤔 (still within the context of having it as bool/string-type property in |
Updated the |
const amount = numFrom(amountLike); | ||
const isForChange = reason?.isForChange ?? false; | ||
super( | ||
`Insufficient CKB, need ${fixedPointToString(amount)} extra CKB${isForChange ? " for the change cell" : ""}`, |
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!! 👍
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.
⭐️⭐️⭐️⭐️ (5/5)
I submitted all the issues I slowly found out over months: they have been analyzed in dept and solved brilliantly in the blink of an eye, while also minimizing compatibility breakage. Excellent quality!! 👍
Definitely recommended, I will hang around here again!
Phroi %93 😁
Thank you for all the contributions! Without you, we wouldn't be able to keep making this better and better. Together, we will make development in the UTXO ecosystem easier. |
A canary version has been published for us to test: Feel free to open an issue for any problems! We will publish the next stable version as soon as it's ready. |
No description provided.