Skip to content

Commit dbb03a4

Browse files
RomarQpepoviola
andauthored
Fix moonbeam chain spec customizations (#1957)
* fix moonbeam chain spec customizations * fix logic --------- Co-authored-by: Javier Viola <[email protected]>
1 parent ebf9a62 commit dbb03a4

File tree

1 file changed

+17
-22
lines changed
  • javascript/packages/orchestrator/src/chain-decorators

1 file changed

+17
-22
lines changed

javascript/packages/orchestrator/src/chain-decorators/moonbeam.ts

+17-22
Original file line numberDiff line numberDiff line change
@@ -126,37 +126,32 @@ async function addParaCustom(specPath: string, node: Node) {
126126
const chainSpec = readAndParseChainSpec(specPath);
127127
const runtimeConfig = getRuntimeConfig(chainSpec);
128128

129-
// parachainStaking
130129
if (!runtimeConfig?.parachainStaking) return;
131130

132131
const { eth_account } = node.accounts;
133132

134-
const stakingBond = paraStakingBond || BigInt("1000000000000000000000");
135-
const reservedBalance = BigInt("100000000000000000000");
133+
const stakingBond = paraStakingBond || BigInt("2000000000000000000000000");
134+
const reservedBalance = BigInt("100000000000000000000000");
136135

137136
// Ensure collator account has enough balance to bond and add candidate
138-
const node_index = runtimeConfig.balances.balances.findIndex(
139-
(item: [string, BigInt]) => {
140-
return item[0] === eth_account.address.toLowerCase();
141-
},
137+
const collatorBalance = runtimeConfig.balances.balances.find(
138+
([address]: [string, BigInt]) =>
139+
address === eth_account.address.toLowerCase(),
142140
);
143141

144-
if (node_index > -1) runtimeConfig.balances.balances.splice(node_index, 1);
145-
146-
runtimeConfig.balances.balances.push([
147-
eth_account.address,
148-
stakingBond + reservedBalance,
149-
]);
150-
151-
const candidate_index = runtimeConfig.balances.balances.findIndex(
152-
(item: [string, BigInt]) => {
153-
return item[0] === eth_account.address.toLowerCase();
154-
},
155-
);
156-
157-
if (candidate_index > -1)
158-
runtimeConfig.balances.balances.splice(candidate_index, 1);
142+
const expectedBalance = stakingBond + reservedBalance;
143+
if (collatorBalance) {
144+
if (collatorBalance[1] < expectedBalance) {
145+
collatorBalance[1] = expectedBalance;
146+
}
147+
} else {
148+
runtimeConfig.balances.balances.push([
149+
eth_account.address,
150+
expectedBalance,
151+
]);
152+
}
159153

154+
// Add collator account as candidate
160155
runtimeConfig.parachainStaking.candidates.push([
161156
eth_account.address,
162157
stakingBond,

0 commit comments

Comments
 (0)