@agoric/orchestration 0.1.1-dev-4687f0d.0 → 0.1.1-dev-1d94913.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,6 +3,7 @@ import { E, Far } from '@endo/far';
3
3
  import { makeMarshal } from '@endo/marshal';
4
4
  import { Fail } from '@agoric/assert';
5
5
  import { registerChainNamespace } from '../chain-info.js';
6
+ import { CHAIN_KEY, CONNECTIONS_KEY } from '../utils/chainHub.js';
6
7
 
7
8
  const trace = makeTracer('CoreEvalOrchestration', true);
8
9
 
@@ -73,7 +74,6 @@ export const setupOrchestrationVat = async (
73
74
  * @param {ERef<import('@agoric/vats').NameHubKit['nameAdmin']>} agoricNamesAdmin
74
75
  * @param {ERef<StorageNode | null>} chainStorageP
75
76
  */
76
-
77
77
  const publishChainInfoToChainStorage = async (
78
78
  agoricNamesAdmin,
79
79
  chainStorageP,
@@ -84,29 +84,48 @@ const publishChainInfoToChainStorage = async (
84
84
  return;
85
85
  }
86
86
 
87
- const chainNamesNode = E(
88
- E(chainStorage).makeChildNode('agoricNames'),
89
- ).makeChildNode('chain');
90
- const { nameAdmin } = await E(agoricNamesAdmin).provideChild('chain');
91
-
92
- await E(nameAdmin).onUpdate(
93
- // XXX will live on the heap in the bootstrap vat. When we upgrade or kill
94
- // that this handler will sever and vat-agoricNames will need to be upgraded
95
- // to allow changing the handler, or to use pubsub mechanics instead.
96
- Far('chain info writer', {
97
- write(entries) {
98
- // chainInfo has no cap data but we need to marshal bigints
99
- const marshalData = makeMarshal(_val => Fail`data only`);
100
- for (const [chainName, info] of entries) {
101
- // XXX writes even if the entry hasn't changed
102
- const chainNode = E(chainNamesNode).makeChildNode(chainName);
103
- void E(chainNode).setValue(
104
- JSON.stringify(marshalData.toCapData(info)),
105
- );
106
- }
107
- },
108
- }),
109
- );
87
+ const agoricNamesNode = await E(chainStorage).makeChildNode('agoricNames');
88
+
89
+ /**
90
+ * @param {string} subpath
91
+ */
92
+ const echoNameUpdates = async subpath => {
93
+ const chainNamesNode = E(agoricNamesNode).makeChildNode(subpath);
94
+ const { nameAdmin } = await E(agoricNamesAdmin).provideChild(subpath);
95
+
96
+ /**
97
+ * Previous entries, to prevent redundant updates
98
+ *
99
+ * @type {Record<string, string>} chainName => stringified chainInfo
100
+ */
101
+ const prev = {};
102
+
103
+ // XXX cannot be changed until we upgrade vat-agoricNames to allow it
104
+ await E(nameAdmin).onUpdate(
105
+ // XXX will live on the heap in the bootstrap vat. When we upgrade or kill
106
+ // that this handler will sever and vat-agoricNames will need to be upgraded
107
+ // to allow changing the handler, or to use pubsub mechanics instead.
108
+ Far('chain info writer', {
109
+ write(entries) {
110
+ // chainInfo has no cap data but we need to marshal bigints
111
+ const marshalData = makeMarshal(_val => Fail`data only`);
112
+ for (const [chainName, info] of entries) {
113
+ const value = JSON.stringify(marshalData.toCapData(info));
114
+ if (prev[chainName] === value) {
115
+ continue;
116
+ }
117
+ const chainNode = E(chainNamesNode).makeChildNode(chainName);
118
+ prev[chainName] = value;
119
+ void E(chainNode)
120
+ .setValue(value)
121
+ .catch(() => delete prev[chainName]);
122
+ }
123
+ },
124
+ }),
125
+ );
126
+ };
127
+ await echoNameUpdates(CHAIN_KEY);
128
+ await echoNameUpdates(CONNECTIONS_KEY);
110
129
  };
111
130
 
112
131
  /**