Skip to content

Commit

Permalink
Merge pull request #4341 from iron-fish/staging
Browse files Browse the repository at this point in the history
STAGING -> MASTER
  • Loading branch information
danield9tqh authored Oct 5, 2023
2 parents a584239 + 9d6d289 commit c898a1e
Show file tree
Hide file tree
Showing 89 changed files with 218 additions and 178 deletions.
2 changes: 1 addition & 1 deletion ironfish/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ironfish/sdk",
"version": "1.10.0",
"version": "1.10.1",
"description": "SDK for running and interacting with an Iron Fish node",
"author": "Iron Fish <[email protected]> (https://ironfish.network)",
"main": "build/src/index.js",
Expand Down
3 changes: 0 additions & 3 deletions ironfish/src/fileStores/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export type ConfigOptions = {
* The max number of node workers. See config "nodeWorkers"
*/
nodeWorkersMax: number
p2pSimulateLatency: number
peerPort: number
rpcTcpHost: string
rpcTcpPort: number
Expand Down Expand Up @@ -335,7 +334,6 @@ export const ConfigOptionsSchema: yup.ObjectSchema<Partial<ConfigOptions>> = yup
nodeName: yup.string(),
nodeWorkers: yup.number().integer().min(-1),
nodeWorkersMax: yup.number().integer().min(-1),
p2pSimulateLatency: YupUtils.isPositiveInteger,
peerPort: YupUtils.isPort,
rpcTcpHost: yup.string().trim(),
rpcTcpPort: YupUtils.isPort,
Expand Down Expand Up @@ -442,7 +440,6 @@ export class Config extends KeyStore<ConfigOptions> {
nodeName: '',
nodeWorkers: -1,
nodeWorkersMax: 6,
p2pSimulateLatency: 0,
peerPort: DEFAULT_WEBSOCKET_PORT,
rpcTcpHost: 'localhost',
rpcTcpPort: 8020,
Expand Down
1 change: 1 addition & 0 deletions ironfish/src/fileStores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './fileStore'
export * from './hosts'
export * from './internal'
export * from './verifiedAssets'
export * from './keyStore'
2 changes: 0 additions & 2 deletions ironfish/src/network/peerNetwork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class PeerNetwork {
targetPeers?: number
enableSyncing?: boolean
logPeerMessages?: boolean
simulateLatency?: number
logger?: Logger
metrics?: MetricsMonitor
telemetry: Telemetry
Expand Down Expand Up @@ -196,7 +195,6 @@ export class PeerNetwork {

this.localPeer.port = options.port === undefined ? null : options.port
this.localPeer.name = options.name || null
this.localPeer.simulateLatency = options.simulateLatency || 0

const maxPeers = options.maxPeers || 10000
const targetPeers = options.targetPeers || 50
Expand Down
43 changes: 0 additions & 43 deletions ironfish/src/network/peers/connections/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ export abstract class Connection {
readonly direction: ConnectionDirection
private handshakeTimeout: SetTimeoutToken | null = null

/**
* If set will simulate a random amount of latency up to this number
*/
protected readonly simulateLatency: number = 0
protected readonly simulateLatencyQueue: Array<NetworkMessage>

/**
* The last error received (if any), regardless of the current state of the connection.
*/
Expand Down Expand Up @@ -105,15 +99,12 @@ export abstract class Connection {
direction: ConnectionDirection,
logger: Logger,
metrics?: MetricsMonitor,
options: { simulateLatency?: number } = {},
) {
this.type = type
this.direction = direction
this.logger = logger
this.metrics = metrics || null
this._error = null
this.simulateLatency = options.simulateLatency || 0
this.simulateLatencyQueue = []
}

send(object: NetworkMessage): boolean {
Expand Down Expand Up @@ -204,40 +195,6 @@ export abstract class Connection {
this.onStateChanged.emit()
}

/**
* Replaces the connection.send() function with one that randomly delays outbound messages
*/
protected addLatencyWrapper(): void {
if (!this.simulateLatency) {
return
}
const originalSend = this.send.bind(this)

const wrapper = (
...args: Parameters<typeof originalSend>
): ReturnType<typeof originalSend> => {
const message = args[0]
this.simulateLatencyQueue.push(message)

let latency = Math.random() * (this.simulateLatency || 0)
if (args[0].type === NetworkMessageType.Disconnecting) {
latency = 0
}

setTimeout(() => {
const toSend = this.simulateLatencyQueue.shift()
if (this.state.type !== 'DISCONNECTED' && toSend) {
originalSend(toSend)
}
}, latency)

// TODO: Not currently possible to propagate connection errors from sending
return true
}

this.send = wrapper
}

shouldLogMessageType(messageType: NetworkMessageType): boolean {
const bannedMessageTypes = [NetworkMessageType.PeerList, NetworkMessageType.Signal]
return !bannedMessageTypes.includes(messageType)
Expand Down
7 changes: 1 addition & 6 deletions ironfish/src/network/peers/connections/webRtcConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,15 @@ export class WebRtcConnection extends Connection {
initiator: boolean,
logger: Logger,
metrics?: MetricsMonitor,
options: { simulateLatency?: number; stunServers?: string[] } = {},
options: { stunServers?: string[] } = {},
) {
super(
ConnectionType.WebRtc,
initiator ? ConnectionDirection.Outbound : ConnectionDirection.Inbound,
logger.withTag('webrtcconnection'),
metrics,
options,
)

if (this.simulateLatency) {
this.addLatencyWrapper()
}

this.peer = new nodeDataChannel.PeerConnection('peer', {
iceServers: options.stunServers ?? [],
maxMessageSize: MAX_MESSAGE_SIZE,
Expand Down
14 changes: 2 additions & 12 deletions ironfish/src/network/peers/connections/webSocketConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,14 @@ export class WebSocketConnection extends Connection {
direction: ConnectionDirection,
logger: Logger,
metrics?: MetricsMonitor,
options: { simulateLatency?: number; hostname?: string; port?: number } = {},
options: { hostname?: string; port?: number } = {},
) {
super(
ConnectionType.WebSocket,
direction,
logger.withTag('WebSocketConnection'),
metrics,
options,
)
super(ConnectionType.WebSocket, direction, logger.withTag('WebSocketConnection'), metrics)

this.socket = socket
this.hostname = options.hostname
this.port = options.port

if (this.simulateLatency) {
this.addLatencyWrapper()
}

if (this.socket.readyState === this.socket.OPEN) {
this.setState({ type: 'WAITING_FOR_IDENTITY' })
} else {
Expand Down
2 changes: 0 additions & 2 deletions ironfish/src/network/peers/localPeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ export class LocalPeer {
port: number | null
// optional a human readable name for the node
name: string | null
// simulated latency in MS that gets added to connection.send
simulateLatency = 0

constructor(
identity: PrivateIdentity,
Expand Down
2 changes: 0 additions & 2 deletions ironfish/src/network/peers/peerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,6 @@ export class PeerManager {
port: number | null,
): WebSocketConnection {
const connection = new WebSocketConnection(ws, direction, this.logger, this.metrics, {
simulateLatency: this.localPeer.simulateLatency,
hostname: hostname || undefined,
port: port || undefined,
})
Expand All @@ -330,7 +329,6 @@ export class PeerManager {
*/
private initWebRtcConnection(peer: Peer, initiator: boolean): WebRtcConnection {
const connection = new WebRtcConnection(initiator, this.logger, this.metrics, {
simulateLatency: this.localPeer.simulateLatency,
stunServers: this.stunServers,
})

Expand Down
1 change: 0 additions & 1 deletion ironfish/src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export class FullNode {
enableSyncing: config.get('enableSyncing'),
targetPeers: config.get('targetPeers'),
logPeerMessages: config.get('logPeerMessages'),
simulateLatency: config.get('p2pSimulateLatency'),
bootstrapNodes: config.getArray('bootstrapNodes'),
stunServers: config.getArray('p2pStunServers'),
webSocket: webSocket,
Expand Down
25 changes: 9 additions & 16 deletions ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
/* 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 { Logger } from '../../logger'
import { RpcResponse, RpcResponseEnded } from '../response'
import {
import type { RpcResponse, RpcResponseEnded } from '../response'
import type {
AcceptTransactionRequest,
AcceptTransactionResponse,
AddPeerRequest,
AddPeerResponse,
AddTransactionRequest,
AddTransactionResponse,
ApiNamespace,
BlockTemplateStreamRequest,
BlockTemplateStreamResponse,
BroadcastTransactionRequest,
Expand Down Expand Up @@ -75,6 +73,8 @@ import {
GetNetworkInfoResponse,
GetNodeStatusRequest,
GetNodeStatusResponse,
GetNotesRequest,
GetNotesResponse,
GetNoteWitnessRequest,
GetNoteWitnessResponse,
GetPeerMessagesRequest,
Expand All @@ -91,10 +91,14 @@ import {
GetTransactionResponse,
GetTransactionStreamRequest,
GetTransactionStreamResponse,
GetWalletAssetRequest,
GetWalletAssetResponse,
GetWorkersStatusRequest,
GetWorkersStatusResponse,
ImportAccountRequest,
ImportResponse,
IsValidPublicAddressRequest,
IsValidPublicAddressResponse,
MintAssetRequest,
MintAssetResponse,
OnGossipRequest,
Expand Down Expand Up @@ -127,20 +131,9 @@ import {
UseAccountRequest,
UseAccountResponse,
} from '../routes'
import {
IsValidPublicAddressRequest,
IsValidPublicAddressResponse,
} from '../routes/chain/isValidPublicAddress'
import { GetWalletAssetRequest, GetWalletAssetResponse } from '../routes/wallet/getAsset'
import { GetNotesRequest, GetNotesResponse } from '../routes/wallet/getNotes'
import { ApiNamespace } from '../routes/namespaces'

export abstract class RpcClient {
readonly logger: Logger

constructor(logger: Logger) {
this.logger = logger
}

abstract request<TEnd = unknown, TStream = unknown>(
route: string,
data?: unknown,
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/memoryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class RpcMemoryClient extends RpcClient {
router?: Router

constructor(logger: Logger, router?: Router) {
super(logger)
super()
this.router = router
}

Expand Down
8 changes: 5 additions & 3 deletions ironfish/src/rpc/clients/socketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import net from 'net'
import { Assert } from '../../assert'
import { Event } from '../../event'
import { createRootLogger, Logger } from '../../logger'
import { Logger } from '../../logger'
import { ErrorUtils, PromiseUtils, SetTimeoutToken, YupUtils } from '../../utils'
import {
MESSAGE_DELIMITER,
Expand Down Expand Up @@ -37,12 +37,14 @@ export abstract class RpcSocketClient extends RpcClient {
readonly connectTo: RpcSocketClientConnectionInfo
readonly authToken: string | null = null
readonly messageBuffer: MessageBuffer
protected readonly logger: Logger

client: net.Socket | null = null
isConnected = false

constructor(connectTo: RpcSocketClientConnectionInfo, logger?: Logger, authToken?: string) {
super(logger ?? createRootLogger())
constructor(connectTo: RpcSocketClientConnectionInfo, logger: Logger, authToken?: string) {
super()
this.logger = logger
this.connectTo = connectTo
this.authToken = authToken ?? null
this.messageBuffer = new MessageBuffer()
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/broadcastTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { Transaction } from '../../../primitives'
import { ValidationError } from '../../adapters'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type BroadcastTransactionRequest = {
transaction: string
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/estimateFeeRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Assert } from '../../../assert'
import { PRIORITY_LEVELS, PriorityLevel } from '../../../memPool/feeEstimator'
import { FullNode } from '../../../node'
import { CurrencyUtils } from '../../../utils'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type EstimateFeeRateRequest = { priority?: PriorityLevel } | undefined

Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/estimateFeeRates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import * as yup from 'yup'
import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { CurrencyUtils } from '../../../utils'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type EstimateFeeRatesRequest = undefined
export type EstimateFeeRatesResponse = {
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/exportChainStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { BlockchainUtils } from '../../../utils/blockchain'
import { RpcBlockHeader, RpcBlockHeaderSchema, serializeRpcBlockHeader } from '../../types'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type ExportChainStreamRequest =
| {
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/followChainStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { Block, BlockHeader } from '../../../primitives'
import { BlockHashSerdeInstance } from '../../../serde'
import { BufferUtils, PromiseUtils } from '../../../utils'
import { RpcBlock, RpcBlockSchema, serializeRpcBlockHeader } from '../../types'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type FollowChainStreamRequest =
| {
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { CurrencyUtils } from '../../../utils'
import { AssetStatus } from '../../../wallet'
import { NotFoundError, ValidationError } from '../../adapters'
import { RpcAsset, RpcAssetSchema } from '../../types'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type GetAssetRequest = {
id: string
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/getBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { GENESIS_BLOCK_SEQUENCE } from '../../../primitives/block'
import { BufferUtils } from '../../../utils'
import { NotFoundError, ValidationError } from '../../adapters'
import { RpcBlock, RpcBlockSchema, serializeRpcBlockHeader } from '../../types'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type GetBlockRequest = {
search?: string
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/getChainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { GENESIS_BLOCK_SEQUENCE } from '../../../primitives/block'
import { BlockHashSerdeInstance } from '../../../serde'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type BlockIdentifier = { index: string; hash: string }

Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/getConsensusParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import * as yup from 'yup'
import { Assert } from '../../../assert'
import { FullNode } from '../../../node'
import { ApiNamespace, routes } from '../router'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

interface ConsensusParameters {
allowedBlockFuturesSeconds: number
Expand Down
Loading

0 comments on commit c898a1e

Please sign in to comment.