-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathprepareNodeConfig.ts
More file actions
188 lines (174 loc) Β· 5.75 KB
/
prepareNodeConfig.ts
File metadata and controls
188 lines (174 loc) Β· 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import { NodeConfig } from './types/NodeConfig.generated';
import {
NodeConfigChainInfoJson,
NodeConfigDataAvailabilityRpcAggregatorBackendsJson,
} from './types/NodeConfig';
import { ChainConfig } from './types/ChainConfig';
import { CoreContracts } from './types/CoreContracts';
import { ParentChainId, validateParentChain } from './types/ParentChain';
import { getParentChainLayer } from './utils';
import { parentChainIsArbitrum } from './parentChainIsArbitrum';
// this is different from `sanitizePrivateKey` from utils, as this removes the 0x prefix
function sanitizePrivateKey(privateKey: string) {
return privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
}
function stringifyInfoJson(infoJson: NodeConfigChainInfoJson): string {
return JSON.stringify(infoJson);
}
function stringifyBackendsJson(
backendsJson: NodeConfigDataAvailabilityRpcAggregatorBackendsJson,
): string {
return JSON.stringify(backendsJson);
}
export type PrepareNodeConfigParams = {
chainName: string;
chainConfig: ChainConfig;
coreContracts: CoreContracts;
batchPosterPrivateKey: string;
validatorPrivateKey: string;
stakeToken: string;
parentChainId: ParentChainId;
parentChainIsArbitrum?: boolean;
parentChainRpcUrl: string;
parentChainBeaconRpcUrl?: string;
dasServerUrl?: string;
};
function getDisableBlobReader(parentChainId: ParentChainId): boolean {
if (getParentChainLayer(parentChainId) !== 1 && !parentChainIsArbitrum(parentChainId)) {
return true;
}
return false;
}
export function prepareNodeConfig({
chainName,
chainConfig,
coreContracts,
batchPosterPrivateKey,
validatorPrivateKey,
stakeToken,
parentChainId,
parentChainIsArbitrum: parentChainIsArbitrumParam,
parentChainRpcUrl,
parentChainBeaconRpcUrl,
dasServerUrl,
}: PrepareNodeConfigParams): NodeConfig {
// For L2 Orbit chains settling to Ethereum mainnet or testnet, a parentChainBeaconRpcUrl is enforced
if (getParentChainLayer(parentChainId) === 1 && !parentChainBeaconRpcUrl) {
throw new Error(`"parentChainBeaconRpcUrl" is required for L2 Orbit chains.`);
}
const { chainId: parentChainIdValidated, isCustom: parentChainIsCustom } =
validateParentChain(parentChainId);
if (parentChainIsCustom && typeof parentChainIsArbitrumParam === 'undefined') {
throw new Error(
`"params.parentChainIsArbitrum" must be provided when using a custom parent chain.`,
);
}
const config: NodeConfig = {
'chain': {
'info-json': stringifyInfoJson([
{
'chain-id': chainConfig.chainId,
'parent-chain-id': parentChainId,
'parent-chain-is-arbitrum': parentChainIsCustom
? parentChainIsArbitrumParam!
: parentChainIsArbitrum(parentChainIdValidated),
'chain-name': chainName,
'chain-config': chainConfig,
'rollup': {
'bridge': coreContracts.bridge,
'inbox': coreContracts.inbox,
'sequencer-inbox': coreContracts.sequencerInbox,
'rollup': coreContracts.rollup,
'validator-utils': coreContracts.validatorUtils,
'validator-wallet-creator': coreContracts.validatorWalletCreator,
'stake-token': stakeToken,
'deployed-at': coreContracts.deployedAtBlockNumber,
},
},
]),
'name': chainName,
},
'parent-chain': {
connection: {
url: parentChainRpcUrl,
},
},
'http': {
addr: '0.0.0.0',
port: 8449,
vhosts: ['*'],
corsdomain: ['*'],
api: ['eth', 'net', 'web3', 'arb', 'debug'],
},
'node': {
'sequencer': true,
'delayed-sequencer': {
'enable': true,
'use-merge-finality': false,
'finalize-distance': 1,
},
'batch-poster': {
'max-size': 90000,
'enable': true,
'parent-chain-wallet': {
'private-key': sanitizePrivateKey(batchPosterPrivateKey),
},
},
'staker': {
'enable': true,
'strategy': 'MakeNodes',
'parent-chain-wallet': {
'private-key': sanitizePrivateKey(validatorPrivateKey),
},
},
'dangerous': {
'no-sequencer-coordinator': true,
'disable-blob-reader': getDisableBlobReader(parentChainId),
},
'bold': {
strategy: 'MakeNodes',
},
},
'execution': {
'forwarding-target': '',
'sequencer': {
'enable': true,
'max-tx-data-size': 85000,
'max-block-speed': '250ms',
},
'caching': {
archive: true,
},
},
};
if (parentChainBeaconRpcUrl) {
config['parent-chain']!['blob-client'] = {
'beacon-url': parentChainBeaconRpcUrl,
};
}
const dasServerUrlWithFallback = dasServerUrl ?? 'http://localhost';
if (chainConfig.arbitrum.DataAvailabilityCommittee) {
config.node!['data-availability'] = {
'enable': true,
'sequencer-inbox-address': coreContracts.sequencerInbox,
'parent-chain-node-url': parentChainRpcUrl,
'rest-aggregator': {
enable: true,
urls: [`${dasServerUrlWithFallback}:9877`],
},
'rpc-aggregator': {
'enable': true,
'assumed-honest': 1,
'backends': stringifyBackendsJson([
{
url: `${dasServerUrlWithFallback}:9876`,
pubkey:
'YAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==',
signermask: 1,
},
]),
},
};
}
return config;
}