-
Notifications
You must be signed in to change notification settings - Fork 212
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
refactor: move atomicRearrange into Zcf #7900
Conversation
b6e326b
to
561dadf
Compare
561dadf
to
a178f26
Compare
@@ -184,6 +197,14 @@ | |||
* @returns {Amount<any>} | |||
*/ | |||
|
|||
/** | |||
* @deprecated Use atomicRearrange instead |
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 JSDoc does not support deprecating callbacks. In VSCode there's no strikethrough like other deprecations. I think because incrementBy
property itself isn't deprecated. The notice is from line 223.
To mark these two properties as deprecated we'll have to use .ts
syntax for the types. Unfortunately, that makes is harder to share them ambiently. We could put them in the global namespace but that's not technically correct.
Alternately, we could define the ZCFSeat
type using the concrete implementation, which can also mark things deprecated. I'm fine deferring that.
Meanwhile, please revert making DeprecatedIncrementDecrementBy
as it doesn't do anything :)
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.
Thanks for checking this, and looking for other alternatives. It annoyed me that I couldn't find a way to get a strike-through on incrementBy
and decrementBy
.
@@ -214,6 +216,10 @@ export const createSeatManager = ( | |||
|
|||
return isOfferSafe(state.proposal, reallocation); | |||
}, | |||
/** | |||
* @deprecated switch to zcf.atomicRearrange() |
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.
This is good but note that consumers of this object aren't getting the type written here. They get ZCFSeat
which has the problem discussed above.
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.
Agreed. The comment is mostly for those reading/editing this file. This still seemed the most concise way to express it.
b8f88d7
to
14ac202
Compare
@@ -52,6 +43,8 @@ export const TransferPartShape = M.splitArray( | |||
* which will remain helpers. These helper are for convenience | |||
* in expressing atomic rearrangements clearly. | |||
* | |||
* @deprecated use the zcf builtin instead | |||
* | |||
* @param {ZCF} zcf | |||
* @param {TransferPart[]} transfers | |||
*/ |
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.
If the new code has the same semantics, why not redefine the old code to delegate to the new code?
*/ | |
*/ | |
export const atomicRearrange = (zcf, transfers) => zcf.atomicRearrange(transfers); |
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.
Doh! of course.
fbe162c
to
a7a4fed
Compare
} | ||
|
||
/** @type {[ZCFSeat,AmountKeywordRecord][]} */ | ||
const resultingAllocations = []; |
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.
resultingAllocations
is a different shape than allocations
. consider renaming to resultingEntries
or resolvedEntries
.
consider a functional style using a transform function:
const resolveAllocation = (seat, [incrList, decrList]) => {…};
const resolvedEntries = allocations.entries().map(resolveAllocation);
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 I looked at that, but allocations.entries()
isn't an array. Using Array.from()
would require declaring more types.
([seat, allocation]) => { | ||
const seatHandle = zcfSeatToSeatHandle.get(seat); | ||
return { seatHandle, allocation }; | ||
}, |
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 for concision in map callbacks
([seat, allocation]) => { | |
const seatHandle = zcfSeatToSeatHandle.get(seat); | |
return { seatHandle, allocation }; | |
}, | |
([seat, allocation]) => ({ | |
{ allocation, seatHandle: zcfSeatToSeatHandle.get(seat) }; | |
}), |
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.
done.
It doesn't seem any more concise to me. If prettier had plausible (to me, I admit) rules, it would be better as you show, but prettier formats it as
([seat, allocation]) => ({
allocation,
seatHandle: zcfSeatToSeatHandle.get(seat),
}),
Which is not an improvement, AFAICT. In fact, seeing this, I might extract seatHandle
so the return value will be on one line.
activeZCFSeats.set(seat, allocation), | ||
); | ||
|
||
E(zoeInstanceAdmin).replaceAllocations(seatHandleAllocations); |
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.
this is a promise that may reject. if so it will fail silently.
I see that reallocate
had this same problem. Am I missing something?
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 have tried to ensure that ZCF has the authoritative word here. If ZCF and Zoe lose contact then things are very broken and will shortly fall apart.
Short of that, Zoe and ZCF are in close communication and we have tried to ensure that the two sides remain in sync, and for every shared bit of info, we know which side is authoritative.
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.
Ok. Please put void
and a comment with that justification. In particular, why a failure of replaceAllocations
shouldn't be caught by the catch and shutdownWithFailure
.
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.
done
a7a4fed
to
a16493d
Compare
Just re-requested a review from myself to make this easier for me to find. @ivanlei due to finger error, I also re-requested a review from you. I don't know how to undo that. |
This is the next step of #6577 (atomic reallocations for contracts). It adds native support in ZCF for atomicReallocate, which makes it possible to update contracts from the helper to use the ZCF-native approach, which is a prerequisite for removing the old hazardous staging-based approach. This PR only affects ZCF, though it updates types referenced from inter-protocol contracts. This is required in order to keep the mono-repo consistent, and has no run-time impact on the contracts, even if changes are pushed to some live contracts even before the ZOE change takes effect. The sample contracts in Zoe have also been updated to use the new API. These do not affect the interprotocol contracts. The only zoe contract referenced by inter-protocol contracts is scaledPriceAuthority, which is not changed here. The new code was tested with versions of the inter-protocol contracts updated to use the ZCF-native API. Those contracts were reverted to their old form before merging this PR since the contracts should be updated separately from Zoe. None of the contracts should be updated to use the new reallocation API until this PR is running on chain. They can be individually updated once this code is in place.
a16493d
to
b9c3ff2
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.
One small change requested.
Let's also discuss whether this can land before its upgrade test or should be bundled with it.
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.
🚢
refactor: move atomicRearrange into Zcf
refs: #6678 refs: #7900 ## Description update VaultFactory to use zcf.atomicRearrange. This change **must not** be pushed to the chain before #7900. ### Security Considerations None ### Scaling Considerations None ### Documentation Considerations None ### Testing Considerations None ### Release considerations This requires a change to Zoe (#7900). Since VaultFactory gets upgraded separately from Zoe, this is staged as a separate PR. Once #7900 is on chain, this update can be made, even if it's in the same release cycle, as long as Zoe is upgraded first. This change is independent of changes to other contracts.
refs: #6678 refs: #7900 ## Description update Auction to use `zcf.atomicRearrange()`. This change must not be pushed to the chain before #7900. ### Security Considerations None ### Scaling Considerations None ### Documentation Considerations None ### Testing Considerations None ### Release considerations This requires a change to Zoe (#7900). Since the Auction gets upgraded separately from Zoe, this is staged as a separate PR. Once #7900 is on chain, this update can be made, even if it's in the same release cycle, as long as Zoe is upgraded first. This change is independent of changes to other contracts.
closes: #6678 refs: #7900 ## Description update PSM to use `zcf.atomicRearrange()`. This change must not be pushed to the chain before #7900. ### Security Considerations None ### Scaling Considerations None ### Documentation Considerations None ### Testing Considerations None ### Release considerations This requires a change to Zoe (#7900). Since PSM gets upgraded separately from Zoe, this is staged as a separate PR. Once #7900 is on chain, this update can be made, even if it's in the same release cycle, as long as Zoe is upgraded first. This change is independent of changes to other contracts.
refs: #6678
refs: #6577
Description
This is the next step of #6577 (atomic reallocations for contracts). It adds native support in ZCF for atomicReallocate, which makes it possible to update contracts from the helper to use the ZCF-native approach, which is a prerequisite for removing the old hazardous staging-based approach.
This PR only affects ZCF, though it updates types referenced from inter-protocol contracts. This is required in order to keep the mono-repo consistent, and has no run-time impact on the contracts, even if changes are pushed to some live contracts even before the ZOE change takes effect.
The sample contracts in Zoe have also been updated to use the new API. These do not affect the interprotocol contracts. The only zoe contract referenced by inter-protocol contracts is scaledPriceAuthority, which is not changed here.
The new code was tested with versions of the inter-protocol contracts updated to use the ZCF-native API. Those contracts were reverted to their old form before merging this PR since the contracts should be updated separately from Zoe. None of the contracts should be updated to use the new reallocation API until this PR is running on chain. They can be individually updated once this code is in place.
This PR deprecates all the parts of the old approach, as well as the interim helper. (reallocate, getStagedAllocation, atomicRearrange, incrementBy, decrementBy, and hasStagedAllocation.)
Security Considerations
A step toward removing hazard-prone reallocation via staging.
Scaling Considerations
None.
Documentation Considerations
Document the deprecations and the new approach to reallocation.
Testing Considerations
Validated all the existing contracts (zoe examples, as well as Inter-prorotocol contracts) work with the new approach. The Zoe examples are updated with this PR. The Inter-protocl contracts were reverted, and continue to use the helper.
Added new tests for the function that coverts TransferPart descriptions to new allocations.
Release considerations
This PR adds an API to ZCF within Zoe. It can be released by upgrading the Zoe contract. Existing contracts will continue to work after this change. After this change, individual contracts can be upgraded to migrate to the new API.