-
Notifications
You must be signed in to change notification settings - Fork 42
docs: vstorage reference; chainStorage publishing guide #1016
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8c1942
style(zoe-helpers): markdown lint
dckc 5607e3b
docs: vstorage reference
dckc 2e1afad
docs: prepareRecorderKitMakers reference docs
dckc f5e14f3
docs: publishing to vstorage
dckc 8c3dfaf
docs: links from permissioned deployment to vstorage etc.
dckc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,10 @@ export const main = startSellConcertTicketsContract; | |
|
||
In the top level promise space, we have: | ||
|
||
- **agoricNames**: read-only access to the [agoricNames](../integration/name-services.md#agoricnames-agoricnamesadmin-well-known-names) name service. | ||
- **agoricNames**: read-only access to the [agoricNames](../integration/name-services#agoricnames-agoricnamesadmin-well-known-names) name service. | ||
|
||
- **agoricNamesAdmin**: admin / update access to **agoricNames** and the name hubs it contains. | ||
- **agoricNamesAdmin**: admin / update access to [agoricNames](../integration/name-services#agoricnames-agoricnamesadmin-well-known-names) and the name hubs it contains. | ||
**Warning: this includes access to over-write existing bindings to instances, brands, etc.** | ||
**Warning: this includes the right to over-write existing bindings to instances, brands, etc.** | ||
|
||
- **bankManager**: to manage reflection of cosmos | ||
|
@@ -45,14 +46,14 @@ In the top level promise space, we have: | |
- **board**: the [board](../integration/name-services.md#the-board-publishing-under-arbitrary-names) name service. | ||
**Note: the board only grows; no mechanism to reclaim storage has been established.** | ||
|
||
- **chainStorage**: to make storage nodes to write to vstorage. | ||
**Warning: this includes the right to over-write previously allocated storage nodes.** | ||
- **chainStorage**: to make storage nodes to [write to vstorage](../zoe/pub-to-storage). | ||
**Warning: this includes access to over-write previously allocated storage nodes.** | ||
|
||
- **chainTimerService**: for getting the current timer and setting timer wake-ups; for example, at the conclusion of a governance vote. | ||
**Note: this includes the right to schedule infinitely repeating events.** | ||
- **chainTimerService**: for getting the current [timer](../../reference/repl/timerServices) and setting timer wake-ups; for example, at the conclusion of a governance vote. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aargh! That's way out-of-date. I added a link to the internal doc to #948. |
||
**Note: this includes access to schedule infinitely repeating events.** | ||
|
||
- **priceAuthority**: access to get price quotes and triggers; see [Price Authority Guide](../zoe/price-authority). | ||
|
||
- **priceAuthorityAdmin**: access to add and replace sources of price quotes using [E(priceAuthorityAdmin).registerPriceAuthority()](../../reference/zoe-api/price-authority-admin#e-priceauthorityregistryadmin-registerpriceauthority-priceauthority-brandin-brandout-force) | ||
|
||
- **zoe**: the Zoe service | ||
- **zoe**: the [Zoe service](../../reference/zoe-api//zoe) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
# Publishing to chainStorage | ||
|
||
Contracts can use [notifiers and subscriptions](../js-programming/notifiers) | ||
to publish to clients. To publish data visible to [vstorage queries](../getting-started/contract-rpc#querying-vstorage), contracts should connect | ||
a subscriber to a `chainStorage` node. | ||
|
||
## Deployment Capabilities for Publishing to chainStorage | ||
|
||
In [Adding Parameter Governance to a Contract](../governance/#adding-parameter-governance-to-a-contract), | ||
`storageNode` and `marshaller` are passed to the contract in its `privateArgs` so it can publish to chainStorage. | ||
|
||
In [dapp-agoric-basics](https://github.com/Agoric/dapp-agoric-basics), the `startSwapContract` uses 2 [permitted deployment capabilities](../coreeval/permissions), `chainStorage` and `board` and uses them to make the `privateArgs`: | ||
|
||
```js | ||
const marshaller = await E(board).getPublishingMarshaller(); | ||
const storageNode = await E(chainStorage).makeChildNode(contractName); | ||
``` | ||
|
||
A `Marshaller` is parameterized by functions for mapping unforgeable object identities to plain data slot references and back. Using the [board](../integration/name-services#the-board-publishing-under-arbitrary-names) name service gives consistent slot references across contracts. | ||
As discussed in [Marshalling Amounts and Instances](../getting-started/contract-rpc#marshalling-amounts-and-instances), this lets | ||
off-chain clients use the same `@endo/marshal` API. | ||
|
||
The `chainStorage` node corresponds to the `published` key in the | ||
[vstorage hierarchy](/reference/vstorage-ref). | ||
Using `E(chainStorage).makeChildNode(contractName)` gives the contract | ||
access to write to the `published.swaparoo` key and all keys under it. | ||
|
||
The `swaparoo` contract delegates the rest of publishing governance parameters to the `@agoric/governance` package. | ||
|
||
## Publishing structured data to chainStorage | ||
|
||
Let's look at the Inter Protocol [assetReserve.js](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/reserve/assetReserve.js) contract to get more of the details. It publishes to [published.reserve.metrics](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/test/reserve/snapshots/test-reserve.js.md) data of the form | ||
|
||
```js | ||
/** | ||
* @typedef {object} MetricsNotification | ||
* @property {AmountKeywordRecord} allocations | ||
* @property {Amount<'nat'>} shortfallBalance shortfall from liquidation that | ||
* has not yet been compensated. | ||
* @property {Amount<'nat'>} totalFeeMinted total Fee tokens minted to date | ||
* @property {Amount<'nat'>} totalFeeBurned total Fee tokens burned to date | ||
*/ | ||
``` | ||
|
||
For example: | ||
|
||
```js | ||
{ | ||
allocations: { | ||
Fee: { | ||
brand: Object @Alleged: IST brand {}, | ||
value: 64561373455n, | ||
}, | ||
ATOM: { | ||
brand: Object @Alleged: ATOM brand {}, | ||
value: 6587020n | ||
}, | ||
}, | ||
shortfallBalance: { | ||
brand: Object @Alleged: IST brand {}, | ||
value: 5747205025n, | ||
}, | ||
totalFeeBurned: { | ||
brand: Object @Alleged: IST brand {}, | ||
value: n, | ||
}, | ||
totalFeeMinted: { | ||
brand: Object @Alleged: IST brand {}, | ||
value: 0n, | ||
}, | ||
}, | ||
``` | ||
|
||
The method that writes this data is: | ||
|
||
```js | ||
writeMetrics() { | ||
const { state } = this; | ||
const metrics = harden({ | ||
allocations: state.collateralSeat.getCurrentAllocation(), | ||
shortfallBalance: state.shortfallBalance, | ||
totalFeeMinted: state.totalFeeMinted, | ||
totalFeeBurned: state.totalFeeBurned, | ||
}); | ||
void state.metricsKit.recorder.write(metrics); | ||
}, | ||
``` | ||
|
||
The `metricsKit` is made with a `makeRecorderKit` function: | ||
|
||
```js | ||
metricsKit: makeRecorderKit( | ||
metricsNode, | ||
/** @type {import('@agoric/zoe/src/contractSupport/recorder.js').TypedMatcher<MetricsNotification>} */ ( | ||
M.any() | ||
), | ||
), | ||
``` | ||
|
||
We "prepare" (in the [exo](https://endojs.github.io/endo/modules/_endo_exo.html) sense) that function for making | ||
a `RecorderKit` using [prepareRecorderKitMakers](/reference/zoe-api/zoe-helpers#preparerecorderkitmakers-baggage-marshaller). | ||
|
||
```js | ||
const { makeRecorderKit } = prepareRecorderKitMakers( | ||
baggage, | ||
privateArgs.marshaller, | ||
); | ||
``` | ||
|
||
The contract gets `baggage`, along with `privateArgs` when it starts in | ||
[the usual way for upgradable contracts](./contract-upgrade.html#upgradable-declaration): | ||
|
||
```js | ||
/** | ||
* Asset Reserve holds onto assets for the Inter Protocol, and ... | ||
* | ||
* @param {{ | ||
* ... | ||
* marshaller: ERef<Marshaller>, | ||
* storageNode: ERef<StorageNode>, | ||
* }} privateArgs | ||
* @param {Baggage} baggage | ||
*/ | ||
export const prepare = async (zcf, privateArgs, baggage) => { | ||
... | ||
}; | ||
``` | ||
|
||
The reserve uses its `StorageNode` and makes a child to get `metricsNode`: | ||
|
||
```js | ||
const metricsNode = await E(storageNode).makeChildNode('metrics'); | ||
``` | ||
|
||
The `marshaller` is used to serialize data structures such as `MetricsNotification` above. | ||
|
||
### Deployment Capabilities for the reserve | ||
|
||
To start `assetReserve`, the [setupReserve](https://github.com/Agoric/agoric-sdk/blob/agoric-upgrade-13/packages/inter-protocol/src/proposals/econ-behaviors.js#L76) function again supplies | ||
the two relevant `privateArgs`, `marshaller` and `storageNode`: | ||
|
||
```js | ||
const STORAGE_PATH = 'reserve'; | ||
const storageNode = await E(storageNode).makeChildNode(STORAGE_PATH); | ||
const marshaller = await E(board).getReadonlyMarshaller(); | ||
``` | ||
|
||
The `setupReserve` function gets `chainStorage` and `board` deployment capabilities passed in: | ||
|
||
```js | ||
export const setupReserve = async ({ | ||
consume: { | ||
board, | ||
chainStorage, | ||
... | ||
}, | ||
... | ||
}) => { ... }; | ||
``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.