Skip to content
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

9207 fake bank #9402

Merged
merged 9 commits into from
May 24, 2024
Merged

9207 fake bank #9402

merged 9 commits into from
May 24, 2024

Conversation

turadg
Copy link
Member

@turadg turadg commented May 22, 2024

refs: #9207

Description

Working balances through makeFakeBankBridge.

Security Considerations

none, test code

Scaling Considerations

none, test code

Documentation Considerations

Contract devs may want to use these utilities eventually. I think they're too early to document yet.

Testing Considerations

per se

Upgrade Considerations

none, test code

@turadg turadg changed the base branch from master to 9207-bridge May 22, 2024 23:37
Copy link

cloudflare-workers-and-pages bot commented May 22, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: ce7886e
Status: ✅  Deploy successful!
Preview URL: https://6aedfe14.agoric-sdk.pages.dev
Branch Preview URL: https://9207-fake-bank.agoric-sdk.pages.dev

View logs

Base automatically changed from 9207-bridge to master May 23, 2024 00:06
@turadg turadg force-pushed the 9207-fake-bank branch 3 times, most recently from 2cc5bbb to 14f700a Compare May 23, 2024 18:18
@turadg turadg requested a review from 0xpatrickdev May 23, 2024 18:19
@turadg turadg marked this pull request as ready for review May 23, 2024 18:20
@@ -882,25 +881,27 @@ export function buildRootObject(_vatPowers, _args, baggage) {
'denomToAddressUpdater',
);

/** @param {ERef<import('./types.js').ScopedBridgeManager<'bank'>>} [bankBridgeMgr] */
async function getBankChannel(bankBridgeMgr) {
async function getBankChannel() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this change mean vat-bank needs to be upgraded with the next release?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a refactor that shouldn't affect the behavior. @michaelfig WDYT, should I revert?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked carefully, but if the only call to getBankChannel is on line 903-904, I'm okay with the refactor.

packages/vats/test/vat-bank.test.js Show resolved Hide resolved
packages/vats/tools/fake-bridge.js Show resolved Hide resolved
Comment on lines 53 to 56
retain: M.callWhen(PaymentShape).optional(amountShape).returns(amountShape),
retain: M.callWhen(PaymentShape)
.optional(AmountShapeShape)
.returns(amountShape),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgrade Consideration: That's a change to vat-bank. Are we planning to upgrade it?
If not, we might have to work around this instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dunno but it's a bug in the interface guard. Working around it means never using that parameter.

If you're proposing to remove the parameter rather than fixing it (so nobody using a thing that will break in production) I can get behind that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all amounts are keys, and all keys are patterns, anything that passes the old incorrect amountShape guard (when that is the same as AmountShape) will pass either the new M.pattern() or AmountShapeShape guard, so this seems like a compatible change. It only turns correct-but-rejected arguments into correctly-accepted arguments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, upgrading this in production won't break any code that had managed to run in production before.

My remaining concern is that if we make this fix and don't ship it for a while then in the meantime people may right code that works in dev but will fail when they get to the production chain (or test in a3p). I'll take any changes out fo this PR and leave it for #9407

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...people may right code that works in dev but will fail when they get to the production chain...

yes. that's exactly the upgrade consideration that I have in mind.

I'm proposing that until we have plans to deploy this fix, we don't put any code that depends on it into stuff that we plan to deploy.

If you're proposing to remove the parameter rather than fixing it ...

I hadn't considered that. And I don't advocate it now (though I suppose I wouldn't object to it).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #9410

packages/vats/src/virtual-purse.js Outdated Show resolved Hide resolved
@@ -50,7 +51,9 @@ export const makeVirtualPurseKitIKit = (
});

const RetainRedeemI = M.interface('RetainRedeem', {
retain: M.callWhen(PaymentShape).optional(amountShape).returns(amountShape),
retain: M.callWhen(PaymentShape)
.optional(AmountShapeShape)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original here is definitely a bug. But why not change to

Suggested change
.optional(AmountShapeShape)
.optional(M.pattern())

?
It would be more consistent with the existing ERTP guards.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to abstract this by having ERTP

export AmountShapeShape = M.pattern();

in order to encapsulate that representation decision, that would be fine. But in that case, we should also fix the deposit, receive and burn guards to use the clearer name as well, for consistency.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like having the named shape there, and do the same for the methods for consistency.

But why define AmountShapeShape as simply M.pattern()? Isn't this more accurate and helpful?

/** For parameters that are themselves an AmountShape pattern. */
export const AmountShapeShape = harden({
  brand: M.pattern(),
  value: M.pattern(),
});

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this more accurate and helpful?

It is more precise, in that it admits fewer patterns as valid. But the existing guards in ERTP already admit, for example, M.any() and an optAmountShape argument, which this more precise pattern would reject. So I'd say it is less accurate and helpful because it is overly precise. Were we to make this change consistently, some (hypothetical?) programs that are currently correct would start failing.

See #9410

Comment on lines 53 to 56
retain: M.callWhen(PaymentShape).optional(amountShape).returns(amountShape),
retain: M.callWhen(PaymentShape)
.optional(AmountShapeShape)
.returns(amountShape),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since all amounts are keys, and all keys are patterns, anything that passes the old incorrect amountShape guard (when that is the same as AmountShape) will pass either the new M.pattern() or AmountShapeShape guard, so this seems like a compatible change. It only turns correct-but-rejected arguments into correctly-accepted arguments.

Copy link
Member

@michaelfig michaelfig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. A lot of forward progress!

@turadg turadg added the automerge:rebase Automatically rebase updates, then merge label May 24, 2024
@mergify mergify bot merged commit 60cffcf into master May 24, 2024
71 checks passed
@mergify mergify bot deleted the 9207-fake-bank branch May 24, 2024 17:59
mergify bot pushed a commit that referenced this pull request Aug 8, 2024
closes: XXX
refs: #9402 (comment) #9402 (comment)  #9407

## Description

#9407 explains that sometimes we used a `.optional(AmountShape)` guard to describe an `optAmountShape` argument.

#9402 (comment) #9402 (comment) discussed ways to fix this that were ultimately omitted from #9402 . This PR provides a form of the fix discussed in those comments. Three remaining controversies I'd like my reviewers to comment on:
- Whether the name of the exported pattern should be `AmountShapeShape` or `AmountPatternShape`. See my doc-comment on `AmountPatternShape` for my weak reasoning about why I chose this name.
- If we do go with `AmountPatternShape` for the stated reasons, should the corresponding parameter variables be changed from `optAmountShape` to `optAmountPattern`.
- Whatever the name of the exported pattern, should it be defined as 
   - `M.pattern()`
   - `harden({ brand: M.pattern(), value: M.pattern() })`
   - `harden({ brand: BrandShape, value: M.pattern() })`
   - something else

### Security Considerations

For almost all of the choices of resolving the above controversies, this PR remains a pure bug fix. All correct code that used to work will continue working the same way, and some correct code that used to incorrectly fail due to this bug will now start working correctly.

The exception would be if we both accepting the renaming of some existing occurrences of `M.pattern()` to `AmountPatternShape`/`AmountShapeShape`, and define this name as a pattern narrower than `M.pattern()`. In that case, existing (hypothetical) code that, for example, used `M.any()` in such an argument position would start failing.

### Scaling Considerations

None
### Documentation Considerations

None
### Testing Considerations

#9407 mentions how to reproduce the bug it reports. This PR should add that as a test, to verify that this PR fixes that bug.
### Upgrade Considerations

#9402 (comment) and #9402 (comment) explain the upgrade concern that was likely the cause for omitting this fix from #9042
kriskowal pushed a commit that referenced this pull request Aug 27, 2024
closes: XXX
refs: #9402 (comment) #9402 (comment)  #9407

## Description

#9407 explains that sometimes we used a `.optional(AmountShape)` guard to describe an `optAmountShape` argument.

#9402 (comment) #9402 (comment) discussed ways to fix this that were ultimately omitted from #9402 . This PR provides a form of the fix discussed in those comments. Three remaining controversies I'd like my reviewers to comment on:
- Whether the name of the exported pattern should be `AmountShapeShape` or `AmountPatternShape`. See my doc-comment on `AmountPatternShape` for my weak reasoning about why I chose this name.
- If we do go with `AmountPatternShape` for the stated reasons, should the corresponding parameter variables be changed from `optAmountShape` to `optAmountPattern`.
- Whatever the name of the exported pattern, should it be defined as 
   - `M.pattern()`
   - `harden({ brand: M.pattern(), value: M.pattern() })`
   - `harden({ brand: BrandShape, value: M.pattern() })`
   - something else

### Security Considerations

For almost all of the choices of resolving the above controversies, this PR remains a pure bug fix. All correct code that used to work will continue working the same way, and some correct code that used to incorrectly fail due to this bug will now start working correctly.

The exception would be if we both accepting the renaming of some existing occurrences of `M.pattern()` to `AmountPatternShape`/`AmountShapeShape`, and define this name as a pattern narrower than `M.pattern()`. In that case, existing (hypothetical) code that, for example, used `M.any()` in such an argument position would start failing.

### Scaling Considerations

None
### Documentation Considerations

None
### Testing Considerations

#9407 mentions how to reproduce the bug it reports. This PR should add that as a test, to verify that this PR fixes that bug.
### Upgrade Considerations

#9402 (comment) and #9402 (comment) explain the upgrade concern that was likely the cause for omitting this fix from #9042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants