Skip to content

Commit

Permalink
Combine networks into network files (#4623)
Browse files Browse the repository at this point in the history
  • Loading branch information
NullSoldier authored Jan 27, 2024
1 parent c7b87c6 commit 489d83f
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 93 deletions.
83 changes: 0 additions & 83 deletions ironfish/src/defaultNetworkDefinitions.ts

This file was deleted.

4 changes: 1 addition & 3 deletions ironfish/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ export * from './assert'
export * from './assets'
export * from './blockchain'
export * from './consensus'
export * from './defaultNetworkDefinitions'
export * from './networkDefinition'
export { DEV_GENESIS_ACCOUNT } from './genesisBlocks/devnet'
export * from './networks'
export * from './chainProcessor'
export * from './event'
export * from './fileStores'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import type { NetworkDefinition } from '../networkDefinition'

/**
* This account (IronFishGenesisAccount) can be imported to access the funds in the genesis block.
*
Expand Down Expand Up @@ -50,3 +52,21 @@ export const DEVNET_GENESIS = {
),
],
}

// TODO(IFL-1523): Update proper activation sequence for enableAssetOwnership
export const DEVNET: NetworkDefinition = {
id: 2,
bootstrapNodes: [],
genesis: DEVNET_GENESIS,
consensus: {
allowedBlockFutureSeconds: 15,
genesisSupplyInIron: 42000000,
targetBlockTimeInSeconds: 60,
targetBucketTimeInSeconds: 10,
maxBlockSizeBytes: 524288,
minFee: 0,
enableAssetOwnership: 1,
enforceSequentialBlockTime: 1,
enableFishHash: 'never',
},
}
7 changes: 7 additions & 0 deletions ironfish/src/networks/definitions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

export * from './mainnet'
export * from './testnet'
export * from './devnet'
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import type { NetworkDefinition } from '../networkDefinition'

export const MAINNET_GENESIS = {
header: {
sequence: 1,
Expand Down Expand Up @@ -49,3 +51,24 @@ export const MAINNET_GENESIS = {
),
],
}

// TODO(IFL-1523): Update proper activation sequence for enableAssetOwnership
// enforceSequentialBlockTime activation date is approximately 26-07-2024 00:50. This is not the
// actual date, it's an placeholder for the next hardfork.
// TODO: @ygao76 update this once the hard fork date is finalized.
export const MAINNET: NetworkDefinition = {
id: 1,
bootstrapNodes: ['1.main.bn.ironfish.network', '2.main.bn.ironfish.network'],
genesis: MAINNET_GENESIS,
consensus: {
allowedBlockFutureSeconds: 15,
genesisSupplyInIron: 42000000,
targetBlockTimeInSeconds: 60,
targetBucketTimeInSeconds: 10,
maxBlockSizeBytes: 524288,
minFee: 1,
enableAssetOwnership: 9999999,
enforceSequentialBlockTime: 'never',
enableFishHash: 'never',
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

import type { NetworkDefinition } from '../networkDefinition'

export const TESTNET_GENESIS = {
header: {
sequence: 1,
Expand Down Expand Up @@ -33,3 +35,24 @@ export const TESTNET_GENESIS = {
),
],
}

// TODO(IFL-1523): Update proper activation sequence for enableAssetOwnership
// enforceSequentialBlockTime activation date is approximately 26-07-2024 00:56. This is not the
// actual date, it's an placeholder for the testnet release.
// TODO: @ygao76 update this once the change is ready to release to testnet.
export const TESTNET: NetworkDefinition = {
id: 0,
bootstrapNodes: ['1.test.bn.ironfish.network', '2.test.bn.ironfish.network'],
genesis: TESTNET_GENESIS,
consensus: {
allowedBlockFutureSeconds: 15,
genesisSupplyInIron: 42000000,
targetBlockTimeInSeconds: 60,
targetBucketTimeInSeconds: 10,
maxBlockSizeBytes: 524288,
minFee: 1,
enableAssetOwnership: 9999999,
enforceSequentialBlockTime: 'never',
enableFishHash: 'never',
},
}
6 changes: 6 additions & 0 deletions ironfish/src/networks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

export * from './networkDefinition'
export * from './definitions'
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
import * as yup from 'yup'
import { ActivationSequence, ConsensusParameters } from './consensus'
import { DEVNET, isDefaultNetworkId, MAINNET, TESTNET } from './defaultNetworkDefinitions'
import { Config, InternalStore } from './fileStores'
import { FileSystem } from './fileSystems'
import { SerializedBlock } from './primitives/block'
import { IJSON } from './serde'
import { ActivationSequence, ConsensusParameters } from '../consensus'
import { Config, InternalStore } from '../fileStores'
import { FileSystem } from '../fileSystems'
import { SerializedBlock } from '../primitives/block'
import { IJSON } from '../serde'
import { DEVNET } from './definitions/devnet'
import { MAINNET } from './definitions/mainnet'
import { TESTNET } from './definitions/testnet'

export type NetworkDefinition = {
id: number
Expand Down Expand Up @@ -55,6 +57,21 @@ export const networkDefinitionSchema: yup.ObjectSchema<NetworkDefinition> = yup
})
.defined()

export function isDefaultNetworkId(networkId: number): boolean {
return networkId <= 100
}

export function defaultNetworkName(networkId: number): string | undefined {
switch (networkId) {
case 0:
return 'Testnet'
case 1:
return 'Mainnet'
case 2:
return 'Devnet'
}
}

export async function getNetworkDefinition(
config: Config,
internal: InternalStore,
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { MiningManager } from './mining'
import { PeerNetwork, PrivateIdentity, privateIdentityToIdentity } from './network'
import { isHexSecretKey } from './network/identity'
import { IsomorphicWebSocketConstructor, NodeDataChannelType } from './network/types'
import { getNetworkDefinition } from './networkDefinition'
import { getNetworkDefinition } from './networks'
import { Package } from './package'
import { Platform } from './platform'
import { ALL_API_NAMESPACES, RpcMemoryClient } from './rpc'
Expand Down

0 comments on commit 489d83f

Please sign in to comment.