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

feat: withdrawReward on StakingAccountHolder #9307

Merged
merged 3 commits into from
May 3, 2024
Merged

Conversation

dckc
Copy link
Member

@dckc dckc commented Apr 30, 2024

refs: #9071

I'm not confident this closes #9071; see that issue for questions about scope.

Description

Adds WithdrawReward on invitationMakers of StakingAccountHolder, following the pattern set by Delegate.

Security Considerations

I'm a bit uneasy about lack of guards for the helper facet (helper: UnguardedHelperI). It seems to impose a non-local review burden: we have to be sure every call to the helper facet passes only args that have already been guarded. I tripped on it, once: I passed the wrong type of thing to a helper method and didn't get a helpful guard violation message.

Scaling Considerations

While proportionally, the amount of work done doesn't outgrow the message size (presuming an IBC transaction is O(1)), in absolute terms, it seems unlikely that the fee for a WithdrawReward MsgSpendAction compensates for the cost of the IBC transaction.

Documentation Considerations

It's not entirely clear to me what the status of StakingAccountHolder is. Is it an example? If so, maybe this is docs rather than feat?

Testing Considerations

Based on internal discussions, the tests here are unit tests that mock the rest of the system.

Upgrade Considerations

This presumably gets deployed with the rest of orchestration in an upcoming chain-halting upgrade.

@dckc dckc requested review from turadg and 0xpatrickdev April 30, 2024 01:10
Copy link

cloudflare-workers-and-pages bot commented Apr 30, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: aa79cd5
Status: ✅  Deploy successful!
Preview URL: https://4bf3f91f.agoric-sdk.pages.dev
Branch Preview URL: https://dc-dist-helper.agoric-sdk.pages.dev

View logs

packages/orchestration/src/withdraw-reward.js Outdated Show resolved Hide resolved
packages/orchestration/src/withdraw-reward.js Outdated Show resolved Hide resolved
packages/orchestration/src/withdraw-reward.js Outdated Show resolved Hide resolved
packages/cosmic-proto/package.json Outdated Show resolved Hide resolved
packages/orchestration/src/withdraw-reward.js Outdated Show resolved Hide resolved
@dckc dckc changed the title feat: WithdrawDelegatorReward helper feat: WithdrawReward on StakingAccountHolder Apr 30, 2024
@dckc dckc changed the title feat: WithdrawReward on StakingAccountHolder feat: withdrawReward on StakingAccountHolder Apr 30, 2024
@dckc dckc force-pushed the dc-dist-helper branch 2 times, most recently from f421a92 to a550852 Compare May 2, 2024 16:00
mergify bot added a commit that referenced this pull request May 2, 2024
refs: #9307

## Description

Simplify codegen exports using [exports subpath
patterns](https://nodejs.org/api/packages.html#subpath-patterns)

Reviewers,
- should the exported path have `.js`?
- should Agoric exports be under `agoric` like the others?

### Security Considerations

<!-- Does this change introduce new assumptions or dependencies that, if
violated, could introduce security vulnerabilities? How does this PR
change the boundaries between mutually-suspicious components? What new
authorities are introduced by this change, perhaps by new API calls?
-->

### Scaling Considerations

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations

<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations

<!-- What aspects of this PR are relevant to upgrading live production
systems, and how should they be addressed? -->
@dckc dckc marked this pull request as ready for review May 2, 2024 17:48
* @param {Any} x
* @returns {AnyJson}
*/
const toJSON = x => /** @type {AnyJson} */ (Any.toJSON(x));
Copy link
Member

Choose a reason for hiding this comment

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

consider including "Any" in the fn name

Suggested change
const toJSON = x => /** @type {AnyJson} */ (Any.toJSON(x));
const toAnyJson = x => /** @type {AnyJson} */ (Any.toJSON(x));

*/
async withdrawReward(validator) {
const { chainAddress } = this.state;
const msg0 = MsgWithdrawDelegatorReward.toProtoMsg({
Copy link
Member

Choose a reason for hiding this comment

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

the 0 is distracting. consider removing or making a more explicit message name

};

/**
* XXX defined in codegen/cosmos/base/v1beta1/coin.d.ts
Copy link
Member

Choose a reason for hiding this comment

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

it is now with the subpath pattern

@dckc dckc force-pushed the dc-dist-helper branch from a2ef17e to a804fbe Compare May 2, 2024 18:28
@dckc dckc added the automerge:rebase Automatically rebase updates, then merge label May 2, 2024
@0xpatrickdev
Copy link
Member

Can we also update or add a test in packages/boot/test/bootstrapTests/test-orchestration.ts?

} catch (cause) {
throw assert.error(`bad response: ${ackStr}`, undefined, { cause });
}
};
Copy link
Member

Choose a reason for hiding this comment

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

nb: would be nice to see this pulled out of this file as it seems reusable. This seems like it would be consumer facing for folks implementing custom messages.

@@ -39,16 +43,44 @@ const { Fail } = assert;
const HolderI = M.interface('holder', {
getPublicTopics: M.call().returns(TopicsRecordShape),
makeDelegateInvitation: M.call(M.string(), AmountShape).returns(M.promise()),
makeWithdrawRewardInvitation: M.call(M.string()).returns(M.promise()),
Copy link
Member

Choose a reason for hiding this comment

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

would be nice to add withdrawReward to this interface as well

Copy link
Member Author

Choose a reason for hiding this comment

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

seems like a lot of redundancy: we have each method on 3 facets - twice on the holder facet if we keep that pattern up. Plus all the type declarations and interface guards.

Maybe the methods like makeDelegateInvitation on holder can just go away, since we have Delegate on the invitationMakers facet.

Copy link
Member Author

Choose a reason for hiding this comment

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

given the positive feedback: 8b8f5bd

It's slimmer: +56 -86

return { account, calls };
};

const mockZCF = () => {
Copy link
Member

Choose a reason for hiding this comment

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

Curious, there's nothing we could import here?

Copy link
Member Author

Choose a reason for hiding this comment

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

maybe there is, but I'm not familiar with it.
In this case of build-vs-buy, it seemed easier to write a few lines than to get into the car to go shopping.

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 looked around a bit; I don't see anything in zoe/tools.
The closest I found is zoe/test/unitTests/zcf/setupZcfTest.js, but that has a hard-coded contract.

@dckc dckc force-pushed the dc-dist-helper branch from d20bfc8 to 8b8f5bd Compare May 3, 2024 00:13
dckc added 3 commits May 3, 2024 00:36
 - test: withdrawReward on StakingAccountHolder.helpers facet
 - test tx encoding layers
 - test non-trivial delegations
 - factor out tryDecodeResponse, toJSON
 - todos for remaining work
 - implement delegate() etc. directly on holder;
   - avoids unguarded helper methods
   - since these methods don't have multiple callers,
     it makes little sense to put them on the helper facet anyway
 - call zcf.makeInvitation() directly from invitationMaker facet
   methods; prune makeXInvitation methods on holder
@dckc dckc force-pushed the dc-dist-helper branch from 8b8f5bd to aa79cd5 Compare May 3, 2024 00:36
@mergify mergify bot merged commit dcca603 into master May 3, 2024
67 checks passed
@mergify mergify bot deleted the dc-dist-helper branch May 3, 2024 01:10
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.

orchestration - ICA Controller - Distribution - Withdraw Delegator Reward API
3 participants