-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: upgrade-17 RC1 cherry picks (#10113)
## Description Includes commits from the following PRs: * #10110 Does _not_ include a new upgrade name, because agoric-upgrade-17 has not yet been used in a proposal for any chain. Constructed using the following `git rebase -i HEAD` todo list: ``` # pull request #10110 branch ta/defer-orchestration-agoricNames label base-ta/defer-orchestration-agoricNames pick fc1f3ce fix: write-chain-info after u17 label ta/defer-orchestration-agoricNames reset base-ta/defer-orchestration-agoricNames merge -C 9cdb01d ta/defer-orchestration-agoricNames # fix: write-chain-info after u17 (#10110) ```
- Loading branch information
Showing
6 changed files
with
125 additions
and
93 deletions.
There are no files selected for viewing
This file contains 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
13 changes: 13 additions & 0 deletions
13
packages/builders/scripts/orchestration/write-chain-info.js
This file contains 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,13 @@ | ||
import { makeHelpers } from '@agoric/deploy-script-support'; | ||
|
||
/** @type {import('@agoric/deploy-script-support/src/externalTypes.js').CoreEvalBuilder} */ | ||
export const defaultProposalBuilder = async () => | ||
harden({ | ||
sourceSpec: '@agoric/orchestration/src/proposals/init-chain-info.js', | ||
getManifestCall: ['getManifestForChainInfo'], | ||
}); | ||
|
||
export default async (homeP, endowments) => { | ||
const { writeCoreEval } = await makeHelpers(homeP, endowments); | ||
await writeCoreEval('gov-orchestration', defaultProposalBuilder); | ||
}; |
This file contains 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,98 @@ | ||
import { Fail } from '@endo/errors'; | ||
import { E, Far } from '@endo/far'; | ||
import { makeMarshal } from '@endo/marshal'; | ||
import { makeTracer } from '@agoric/internal'; | ||
import { registerKnownChains } from '../chain-info.js'; | ||
import { CHAIN_KEY, CONNECTIONS_KEY } from '../exos/chain-hub.js'; | ||
|
||
const trace = makeTracer('InitChainInfo', true); | ||
|
||
/** | ||
* Similar to publishAgoricNamesToChainStorage but publishes a node per chain | ||
* instead of one list of entries | ||
*/ | ||
|
||
/** | ||
* @param {ERef<import('@agoric/vats').NameHubKit['nameAdmin']>} agoricNamesAdmin | ||
* @param {ERef<StorageNode | null>} chainStorageP | ||
*/ | ||
const publishChainInfoToChainStorage = async ( | ||
agoricNamesAdmin, | ||
chainStorageP, | ||
) => { | ||
const chainStorage = await chainStorageP; | ||
if (!chainStorage) { | ||
console.warn('no chain storage, not registering chain info'); | ||
return; | ||
} | ||
|
||
const agoricNamesNode = await E(chainStorage).makeChildNode('agoricNames'); | ||
|
||
/** | ||
* @param {string} subpath | ||
*/ | ||
const echoNameUpdates = async subpath => { | ||
const chainNamesNode = E(agoricNamesNode).makeChildNode(subpath); | ||
const { nameAdmin } = await E(agoricNamesAdmin).provideChild(subpath); | ||
|
||
/** | ||
* Previous entries, to prevent redundant updates | ||
* | ||
* @type {Record<string, string>} chainName => stringified chainInfo | ||
*/ | ||
const prev = {}; | ||
|
||
// XXX cannot be changed until we upgrade vat-agoricNames to allow it | ||
await E(nameAdmin).onUpdate( | ||
// XXX will live on the heap in the bootstrap vat. When we upgrade or kill | ||
// that this handler will sever and vat-agoricNames will need to be upgraded | ||
// to allow changing the handler, or to use pubsub mechanics instead. | ||
Far('chain info writer', { | ||
write(entries) { | ||
// chainInfo has no cap data but we need to marshal bigints | ||
const marshalData = makeMarshal(_val => Fail`data only`); | ||
for (const [chainName, info] of entries) { | ||
const value = JSON.stringify(marshalData.toCapData(info)); | ||
if (prev[chainName] === value) { | ||
continue; | ||
} | ||
const chainNode = E(chainNamesNode).makeChildNode(chainName); | ||
prev[chainName] = value; | ||
void E(chainNode) | ||
.setValue(value) | ||
.catch(() => delete prev[chainName]); | ||
} | ||
}, | ||
}), | ||
); | ||
}; | ||
await echoNameUpdates(CHAIN_KEY); | ||
await echoNameUpdates(CONNECTIONS_KEY); | ||
}; | ||
|
||
/** | ||
* @param {BootstrapPowers} powers | ||
*/ | ||
export const initChainInfo = async ({ | ||
consume: { agoricNamesAdmin, chainStorage: chainStorageP }, | ||
}) => { | ||
trace('init-chainInfo'); | ||
|
||
// First set up callback to write updates to vstorage | ||
await publishChainInfoToChainStorage(agoricNamesAdmin, chainStorageP); | ||
|
||
// Now register the names | ||
await registerKnownChains(agoricNamesAdmin, trace); | ||
}; | ||
harden(initChainInfo); | ||
|
||
export const getManifestForChainInfo = () => ({ | ||
manifest: { | ||
[initChainInfo.name]: { | ||
consume: { | ||
agoricNamesAdmin: true, | ||
chainStorage: true, | ||
}, | ||
}, | ||
}, | ||
}); |
This file contains 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 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 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