Skip to content

Commit

Permalink
feat: Allow running nodes in archival mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mfornet committed Feb 10, 2021
1 parent c5c130e commit 21563c0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
29 changes: 22 additions & 7 deletions cli/commands/start/near.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
const util = require('util')
const { execSync } = require('child_process')
const request = require('request')

const { getLocalNearNodeURL } = require('./helpers')
const { readFileSync, writeFileSync } = require('fs')
const { homedir } = require('os')
const { join } = require('path')

const HOME = homedir()
const NEAR_BINARY_PATH = join(HOME, '.rainbow/core/target/debug')

class StartLocalNearNodeCommand {
static execute () {
const command = util.format(
'nearup run localnet --num-nodes 1 --binary-path %s',
'~/.rainbow/core/target/debug'
)
static execute ({ archival }) {
const neardPath = join(NEAR_BINARY_PATH, 'neard')
const localnetPath = join(HOME, '/.near/localnet')
const initConfigCommand = `${neardPath} --home ${localnetPath} testnet --v 1`
const startNodeCommand = `nearup run localnet --num-nodes 1 --binary-path ${NEAR_BINARY_PATH}`

request(getLocalNearNodeURL(), { json: true }, (err, _res, _body) => {
if (err) {
console.log(execSync(command).toString())
console.log(execSync(initConfigCommand).toString())

if (archival === 'true') {
const configPath = join(HOME, '.near/localnet/node0/config.json')
const config = JSON.parse(readFileSync(configPath))
config.archive = true
writeFileSync(configPath, JSON.stringify(config))
}

console.log(execSync(startNodeCommand).toString())
} else {
console.log('Local Node is already running. Skipping...')
}
Expand Down
3 changes: 2 additions & 1 deletion cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ RainbowConfig.declareOption(
RainbowConfig.declareOption('near-erc20-account', 'Must be declared before set')
RainbowConfig.declareOption('total-submit-block', 'Number of blocks to submit on each batch update from Ethereum to NEAR', 4)
RainbowConfig.declareOption('gas-per-transaction', 'Maximum gas per transaction add_block_header', '72000000000000')
RainbowConfig.declareOption('archival', 'Start Near node in archival mode (no garbage collection)', 'false')

program.version(require('./package.json').version)

Expand Down Expand Up @@ -339,7 +340,7 @@ const startCommand = program.command('start')
RainbowConfig.addOptions(
startCommand.command('near-node'),
StartLocalNearNodeCommand.execute,
[]
['archival']
)

RainbowConfig.addOptions(
Expand Down
2 changes: 1 addition & 1 deletion testing/ci/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if [ -n "${LOCAL_CORE_SRC+x}" ]; then
else
node index.js prepare
fi
node index.js start near-node
node index.js start near-node --archival true
node index.js start ganache
# Wait for the local node to start
while ! curl localhost:3030; do
Expand Down

0 comments on commit 21563c0

Please sign in to comment.