-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: write-chain-info after u17 (#10110)
_incidental_ ## Description We don't have a good design yet for the schema of Orchestration chain info in agoricNames, - #10109 It's not necessary for upgrade-17 so save it for another proposal. ### Security Considerations none ### Scaling Considerations none ### Documentation Considerations SDK still registers the info so the development experience doesn't differ. ### Testing Considerations Shouldn't break any existing tests. ### Upgrade Considerations Not yet deployed. Should be part of u17-rc1.
- 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