Skip to content

Commit

Permalink
Merge pull request #37 from Lamden/v2-updates
Browse files Browse the repository at this point in the history
V2 updates
  • Loading branch information
JeffWScott authored Jan 25, 2023
2 parents 2c0a555 + a7aa9b1 commit 81577b7
Show file tree
Hide file tree
Showing 69 changed files with 5,193 additions and 2,733 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
/node_modules/
*.log
*.out
*.out
*.swp
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:gallium-bullseye-slim

RUN apt-get update

ENV ROOT /usr/src/app

WORKDIR ${ROOT}

COPY . ${ROOT}

RUN npm install

CMD [ "npm", "run", "start" ]
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## VERSION 2.0 will not work with a version 1 Lamden network. Use the previuous version to v2 for an old Lamden network.

# Lamden Block Service
A nodejs application for syncing and serving the Lamden Blockchain to a local app.
This application serves as starting point to be able to build an app on Lamden that requires easy access to current state and realtime updates.
Expand All @@ -19,6 +21,7 @@ Features:

### Install App
1. `git clone https://github.com/Lamden/lamden_block_service.git`
2. `cd lamden_block_service`
2. `npm install`

## Run
Expand All @@ -27,6 +30,38 @@ Features:
## Run api doc server
`npm run docs`

## Run Service with docker

Install docker

```
curl -fsSL https://get.docker.com | bash -s docker
```

Then install docker-compose, you can get the latest release at [here](https://github.com/docker/compose/releases)

```
sudo curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
```

Clone this project
```
git clone https://github.com/Dapiguabc/lamden_block_service.git
cd lamden_block_service
```

Build project
```
docker-compose build # build docker image
```

Run the server
```
docker-compose up -d
```



## Sync Chaindata (Optional)
The first time you run the block service, it will take long time to sync blocks data. In order to avoid waiting for so long, you can use
[mongodump](https://www.mongodb.com/docs/database-tools/mongodump/#mongodb-binary-bin.mongodump) to export data from another block service to you own block service.
Expand All @@ -41,6 +76,7 @@ Restart the app for these setting to take effect.
### Lamden configuration items
- NETWORK `testnet`: Which Lamden network to sync
- MASTERNODE_URL `https://testnet-master-1.lamden.io`: A URL of a lamden masternode
- GENESIS_BLOCK_URL (optional): a genesis block url if different than the default Lamden Testnet or Lamden Mainnet genesis blocks

### Mongo DB configuration items
- DBUSER `null`: database user
Expand All @@ -58,6 +94,14 @@ Restart the app for these setting to take effect.
- BLOCKSERVICE_PORT `3535`: The port used for the webserver and websockets
- BLOCKSERVICE_HOST `localhost`: Api bind host

### Api Rate Limit
you can limit the number of api calls for each ip. **This feature is turned off by default.**

- RATE_LIMIT_ENABLE `0`: Enable:1 Disable:0
- RATE_LIMIT_PERIOD `600000`: Time frame for which requests are checked, defaults units is ms
- RATE_LIMIT_NUM `10`: number of api calls


### Misc options
- APIDOC_PORT `8999`: Api document port.
- SCRIPT_SOCKET_CONN `http://localhost:3232`: Estimation script socket server connection.
Expand Down
28 changes: 23 additions & 5 deletions app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,53 @@ import { eventWebsockets } from './src/services/eventsWebsocket.mjs'

import { createServer } from './src/server.mjs'

import { getDatabase } from './src/database/database.mjs'
import { getDatabase, databaseInit } from './src/database/database.mjs'

import { createLogger } from './src/logger.mjs'

import { fixRewardsRecord } from './src/rewardsFix.mjs'

const logger = createLogger('App');

const MASTERNODE_URLS = {
'testnet': "https://testnet-master-1.lamden.io",
'testnet_v2': "https://testnet-v2-master-lon.lamden.io",
'mainnet': "https://masternode-01.lamden.io"
}

const GENESIS_BLOCKS = {
"testnet_v2": "https://raw.githubusercontent.com/Lamden/genesis_block/main/testnet/genesis_block.json",
"staging_v2": "https://raw.githubusercontent.com/Lamden/genesis_block/main/staging/genesis_block.json"
}


/******* MONGO DB CONNECTION INFO **/
const NETWORK = process.env.NETWORK || 'testnet'
const NETWORK = process.env.NETWORK || 'testnet_v2'
const MASTERNODE_URL = process.env.MASTERNODE_URL || MASTERNODE_URLS[NETWORK]

/******* SERVER CONNECTION INFO **/
const BLOCKSERVICE_PORT = process.env.BLOCKSERVICE_PORT || 3535
const BLOCKSERVICE_HOST = process.env.BLOCKSERVICE_HOST || 'localhost'
const GENESIS_BLOCK_URL = process.env.GENESIS_BLOCK_URL || GENESIS_BLOCKS[NETWORK]

let grabberConfig = {
DEBUG_ON: process.env.DEBUG_ON || false,
MASTERNODE_URL
MASTERNODE_URL,
GENESIS_BLOCK_URL
}

export const start = async () => {
// Init database
await databaseInit()

const db = getDatabase()
const server = await createServer(BLOCKSERVICE_HOST, BLOCKSERVICE_PORT, db)

// ensure backward compatibility
await db.models.Blocks.deleteMany({ hash: "block-does-not-exist" })

// parse rewards for old block data in database
await fixRewardsRecord(server.services, db)

logger.info("Syncing Indexes...");
//console.log( db.models)
for (let model_name of Object.keys(db.models)){
Expand All @@ -43,7 +61,7 @@ export const start = async () => {
.then(() => logger.success(`DONE Syncing Indexes for ${db.models[model_name].collection.collectionName}...`))
}

grabberConfig.server = createServer(BLOCKSERVICE_HOST, BLOCKSERVICE_PORT, db)
grabberConfig.server = server
grabberConfig.blockchainEvents = eventWebsockets(grabberConfig.MASTERNODE_URL)

let blockGrabber = runBlockGrabber(grabberConfig)
Expand Down
Loading

0 comments on commit 81577b7

Please sign in to comment.