Skip to content

Commit

Permalink
Fix moonbeam chain spec customizations (#1957)
Browse files Browse the repository at this point in the history
* fix moonbeam chain spec customizations

* fix logic

---------

Co-authored-by: Javier Viola <363911+pepoviola@users.noreply.github.com>
  • Loading branch information
RomarQ and pepoviola authored Feb 12, 2025
1 parent ebf9a62 commit dbb03a4
Showing 1 changed file with 17 additions and 22 deletions.
39 changes: 17 additions & 22 deletions javascript/packages/orchestrator/src/chain-decorators/moonbeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,37 +126,32 @@ async function addParaCustom(specPath: string, node: Node) {
const chainSpec = readAndParseChainSpec(specPath);
const runtimeConfig = getRuntimeConfig(chainSpec);

// parachainStaking
if (!runtimeConfig?.parachainStaking) return;

const { eth_account } = node.accounts;

const stakingBond = paraStakingBond || BigInt("1000000000000000000000");
const reservedBalance = BigInt("100000000000000000000");
const stakingBond = paraStakingBond || BigInt("2000000000000000000000000");
const reservedBalance = BigInt("100000000000000000000000");

// Ensure collator account has enough balance to bond and add candidate
const node_index = runtimeConfig.balances.balances.findIndex(
(item: [string, BigInt]) => {
return item[0] === eth_account.address.toLowerCase();
},
const collatorBalance = runtimeConfig.balances.balances.find(
([address]: [string, BigInt]) =>
address === eth_account.address.toLowerCase(),
);

if (node_index > -1) runtimeConfig.balances.balances.splice(node_index, 1);

runtimeConfig.balances.balances.push([
eth_account.address,
stakingBond + reservedBalance,
]);

const candidate_index = runtimeConfig.balances.balances.findIndex(
(item: [string, BigInt]) => {
return item[0] === eth_account.address.toLowerCase();
},
);

if (candidate_index > -1)
runtimeConfig.balances.balances.splice(candidate_index, 1);
const expectedBalance = stakingBond + reservedBalance;
if (collatorBalance) {
if (collatorBalance[1] < expectedBalance) {
collatorBalance[1] = expectedBalance;
}
} else {
runtimeConfig.balances.balances.push([
eth_account.address,
expectedBalance,
]);
}

// Add collator account as candidate
runtimeConfig.parachainStaking.candidates.push([
eth_account.address,
stakingBond,
Expand Down

0 comments on commit dbb03a4

Please sign in to comment.