From 489d83f481a5fa2b2da74da1fec5c98f94ce2e18 Mon Sep 17 00:00:00 2001 From: Jason Spafford Date: Fri, 26 Jan 2024 16:44:10 -0800 Subject: [PATCH] Combine networks into network files (#4623) --- ironfish/src/defaultNetworkDefinitions.ts | 83 ------------------- ironfish/src/index.ts | 4 +- .../definitions}/devnet.ts | 20 +++++ ironfish/src/networks/definitions/index.ts | 7 ++ .../definitions}/mainnet.ts | 23 +++++ .../definitions}/testnet.ts | 23 +++++ ironfish/src/networks/index.ts | 6 ++ .../src/{ => networks}/networkDefinition.ts | 29 +++++-- ironfish/src/node.ts | 2 +- 9 files changed, 104 insertions(+), 93 deletions(-) delete mode 100644 ironfish/src/defaultNetworkDefinitions.ts rename ironfish/src/{genesisBlocks => networks/definitions}/devnet.ts (90%) create mode 100644 ironfish/src/networks/definitions/index.ts rename ironfish/src/{genesisBlocks => networks/definitions}/mainnet.ts (98%) rename ironfish/src/{genesisBlocks => networks/definitions}/testnet.ts (82%) create mode 100644 ironfish/src/networks/index.ts rename ironfish/src/{ => networks}/networkDefinition.ts (85%) diff --git a/ironfish/src/defaultNetworkDefinitions.ts b/ironfish/src/defaultNetworkDefinitions.ts deleted file mode 100644 index 362eb69acb..0000000000 --- a/ironfish/src/defaultNetworkDefinitions.ts +++ /dev/null @@ -1,83 +0,0 @@ -/* 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/. */ - -import { DEVNET_GENESIS } from './genesisBlocks/devnet' -import { MAINNET_GENESIS } from './genesisBlocks/mainnet' -import { TESTNET_GENESIS } from './genesisBlocks/testnet' -import { NetworkDefinition } from './networkDefinition' - -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' - } -} - -// 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', - }, -} - -// 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', - }, -} - -// 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', - }, -} diff --git a/ironfish/src/index.ts b/ironfish/src/index.ts index de55be0f14..4e245686fe 100644 --- a/ironfish/src/index.ts +++ b/ironfish/src/index.ts @@ -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' diff --git a/ironfish/src/genesisBlocks/devnet.ts b/ironfish/src/networks/definitions/devnet.ts similarity index 90% rename from ironfish/src/genesisBlocks/devnet.ts rename to ironfish/src/networks/definitions/devnet.ts index bf34cb2543..fc4215e13e 100644 --- a/ironfish/src/genesisBlocks/devnet.ts +++ b/ironfish/src/networks/definitions/devnet.ts @@ -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. * @@ -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', + }, +} diff --git a/ironfish/src/networks/definitions/index.ts b/ironfish/src/networks/definitions/index.ts new file mode 100644 index 0000000000..724e4793c9 --- /dev/null +++ b/ironfish/src/networks/definitions/index.ts @@ -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' diff --git a/ironfish/src/genesisBlocks/mainnet.ts b/ironfish/src/networks/definitions/mainnet.ts similarity index 98% rename from ironfish/src/genesisBlocks/mainnet.ts rename to ironfish/src/networks/definitions/mainnet.ts index 153721a30a..e2346a39eb 100644 --- a/ironfish/src/genesisBlocks/mainnet.ts +++ b/ironfish/src/networks/definitions/mainnet.ts @@ -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, @@ -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', + }, +} diff --git a/ironfish/src/genesisBlocks/testnet.ts b/ironfish/src/networks/definitions/testnet.ts similarity index 82% rename from ironfish/src/genesisBlocks/testnet.ts rename to ironfish/src/networks/definitions/testnet.ts index 0b4d963212..8bddb3a02f 100644 --- a/ironfish/src/genesisBlocks/testnet.ts +++ b/ironfish/src/networks/definitions/testnet.ts @@ -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, @@ -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', + }, +} diff --git a/ironfish/src/networks/index.ts b/ironfish/src/networks/index.ts new file mode 100644 index 0000000000..905a0eb891 --- /dev/null +++ b/ironfish/src/networks/index.ts @@ -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' diff --git a/ironfish/src/networkDefinition.ts b/ironfish/src/networks/networkDefinition.ts similarity index 85% rename from ironfish/src/networkDefinition.ts rename to ironfish/src/networks/networkDefinition.ts index 17b97e1881..dd765a3b86 100644 --- a/ironfish/src/networkDefinition.ts +++ b/ironfish/src/networks/networkDefinition.ts @@ -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 @@ -55,6 +57,21 @@ export const networkDefinitionSchema: yup.ObjectSchema = 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, diff --git a/ironfish/src/node.ts b/ironfish/src/node.ts index b5348f2460..6ab43c819e 100644 --- a/ironfish/src/node.ts +++ b/ironfish/src/node.ts @@ -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'