Skip to content

Commit

Permalink
merge dev changes
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ocean committed Aug 6, 2024
2 parents 3561394 + 0c03f69 commit c4c95de
Show file tree
Hide file tree
Showing 12 changed files with 158 additions and 138 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '18.20.4'
node-version: 'v20.16.0'
- name: Cache node_modules
uses: actions/cache@v2
env:
Expand All @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
node: ['18.20.4']
node: ['18.20.4', 'v20.16.0', 'v22.5.1']

steps:
- uses: actions/checkout@v3
Expand All @@ -67,7 +67,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '18.20.4'
node-version: 'v20.16.0'
- name: Cache node_modules
uses: actions/cache@v2
env:
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: '18.20.4'
node-version: 'v20.16.0'
- name: Cache node_modules
uses: actions/cache@v2
env:
Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18.20.4'
node-version: 'v20.16.0'

- name: Cache node_modules
uses: actions/cache@v2
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.20.4
v20.16.0
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY .nvmrc /usr/src/app/
RUN rm /bin/sh && ln -s /bin/bash /bin/sh
ENV NVM_DIR /usr/local/nvm
RUN mkdir $NVM_DIR
ENV NODE_VERSION=v18.20.4
ENV NODE_VERSION=v20.16.0
# Install nvm with node and npm
RUN curl https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
&& source $NVM_DIR/nvm.sh \
Expand Down
29 changes: 0 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"@libp2p/interface-address-manager": "^3.0.1",
"@libp2p/kad-dht": "^12.1.1",
"@libp2p/mdns": "^10.1.1",
"@libp2p/mplex": "^10.1.1",
"@libp2p/peer-id": "^4.1.4",
"@libp2p/peer-id-factory": "^4.1.4",
"@libp2p/ping": "^1.1.1",
Expand Down
25 changes: 17 additions & 8 deletions src/components/Indexer/crawlerThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import {
import { Blockchain } from '../../utils/blockchain.js'
import { BlocksEvents, SupportedNetwork } from '../../@types/blockchain.js'
import { LOG_LEVELS_STR } from '../../utils/logging/Logger.js'
import { sleep } from '../../utils/util.js'
import { isDefined, sleep } from '../../utils/util.js'
import { EVENTS, INDEXER_CRAWLING_EVENTS, INDEXER_MESSAGES } from '../../utils/index.js'
import { INDEXER_LOGGER } from '../../utils/logging/common.js'
import { getDatabase } from '../../utils/database.js'
import { JsonRpcApiProvider, Log, Signer } from 'ethers'
import { DEVELOPMENT_CHAIN_ID } from '../../utils/address.js'

export interface ReindexTask {
txId: string
Expand Down Expand Up @@ -80,13 +81,21 @@ export async function processNetworkData(
signer: Signer
): Promise<void> {
stoppedCrawling = startedCrawling = false
const contractDeploymentBlock = getDeployedContractBlock(rpcDetails.chainId)
if (contractDeploymentBlock == null && (await getLastIndexedBlock()) == null) {
INDEXER_LOGGER.logMessage(
`chain: ${rpcDetails.chainId} Both deployed block and last indexed block are null. Cannot proceed further on this chain`,
true
)
return null
let contractDeploymentBlock = getDeployedContractBlock(rpcDetails.chainId)
if (!isDefined(contractDeploymentBlock) && !isDefined(await getLastIndexedBlock())) {
if (rpcDetails.chainId === DEVELOPMENT_CHAIN_ID) {
rpcDetails.startBlock = contractDeploymentBlock = 0
INDEXER_LOGGER.warn(
'Cannot get block info for local network, starting from block 0'
)
} else {
INDEXER_LOGGER.logMessage(
`chain: ${rpcDetails.chainId} Both deployed block and last indexed block are null/undefined. Cannot proceed further on this chain`,
true
)

return null
}
}
// if we defined a valid startBlock use it, oterwise start from deployed one

Expand Down
41 changes: 26 additions & 15 deletions src/components/P2P/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { bootstrap } from '@libp2p/bootstrap'
import { noise } from '@chainsafe/libp2p-noise'
import { mdns } from '@libp2p/mdns'
import { mplex } from '@libp2p/mplex'
import { yamux } from '@chainsafe/libp2p-yamux'
import { peerIdFromString } from '@libp2p/peer-id'
import { pipe } from 'it-pipe'
Expand Down Expand Up @@ -320,7 +319,7 @@ export class OceanP2P extends EventEmitter {
},
peerId: config.keys.peerId,
transports,
streamMuxers: [yamux(), mplex()],
streamMuxers: [yamux()],
connectionEncryption: [
noise()
// plaintext()
Expand Down Expand Up @@ -550,26 +549,38 @@ export class OceanP2P extends EventEmitter {
let stream
// dial/connect to the target node
try {
// stream= await this._libp2p.dialProtocol(peer, this._protocol)

stream = await this._libp2p.dialProtocol(peerId, this._protocol)
} catch (e) {
response.status.httpStatus = 404
response.status.error = 'Cannot connect to peer'
P2P_LOGGER.error(`Unable to connect to peer: ${peerId}`)
return response
}

response.stream = stream
pipe(
// Source data
[uint8ArrayFromString(message)],
// Write to the stream, and pass its output to the next function
stream,
// this is the anayze function
// doubler as any,
// Sink function
sink
)
if (stream) {
response.stream = stream
try {
await pipe(
// Source data
[uint8ArrayFromString(message)],
// Write to the stream, and pass its output to the next function
stream,
// this is the anayze function
// doubler as any,
// Sink function
sink
)
} catch (err) {
P2P_LOGGER.error(`Unable to send P2P message: ${err.message}`)
response.status.httpStatus = 404
response.status.error = err.message
}
} else {
response.status.httpStatus = 404
response.status.error = 'Unable to get remote P2P stream (null)'
P2P_LOGGER.error(response.status.error)
}

return response
}

Expand Down
Loading

0 comments on commit c4c95de

Please sign in to comment.