Skip to content

Commit

Permalink
Merge pull request #2 from runonbitcoin/timeouts
Browse files Browse the repository at this point in the history
Timeouts
  • Loading branch information
hojarasca committed Jun 24, 2022
2 parents 774833d + 340d58c commit f2f70b4
Show file tree
Hide file tree
Showing 113 changed files with 15,266 additions and 3,819 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
*.sqlite3*
.runcache
.github
.git
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ node_modules
coverage
run.db*
.idea
*.sqlite3
*.sqlite3*
.runcache
docker-compose.override.yml
4 changes: 4 additions & 0 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require: test/setup.js
recursive: true
extension: [".test.js"]
ui: 'bdd-lazy-var/getter'
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage
run.db*
*.sqlite3
.idea
.runcache
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:16

RUN mkdir /app
WORKDIR /app

COPY package.json .
COPY package-lock.json .

RUN npm install --production

COPY . .

CMD ["npm", "start"]
186 changes: 113 additions & 73 deletions README.md

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions blobs-knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
client: 'pg',
connection: process.env.BLOB_DB_CONNECTION_URI || {
user: 'someuser',
password: 'sosecret',
database: 'blobs_regtest'
},
migrations: {
tableName: 'migrations',
directory: 'blobs-migrations'
}
}
28 changes: 28 additions & 0 deletions blobs-migrations/20220316135746_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const RAW_TXS_T = 'raw_transactions'
const JIG_STATES_T = 'jig_states'

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async (knex) => {
await knex.schema.createTable(RAW_TXS_T, t => {
t.text('txid').notNullable().primary()
t.binary('bytes').notNullable()
t.index('txid')
})

await knex.schema.createTable(JIG_STATES_T, t => {
t.text('location').notNullable().primary()
t.jsonb('state').notNullable()
})
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = async (knex) => {
await knex.schema.dropTable('raw_transactions')
await knex.schema.dropTable(JIG_STATES_T)
}
76 changes: 76 additions & 0 deletions db-migrations/20220310174927_initial_migration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
exports.up = async (knex) => {
await knex.schema.createTable('spends', t => {
t.text('location').notNullable().primary()
t.text('spend_txid')
})

await knex.schema.createTable('deps', t => {
t.text('up').notNullable()
t.text('down').notNullable()
t.unique(['up', 'down'])
t.index(['up'], 'deps_up_index')
t.index(['down'], 'deps_down_index')
})

await knex.schema.createTable('jig', t => {
t.text('location').notNullable().primary()
t.jsonb('state')
t.text('class')
t.text('scripthash')
t.text('lock')
t.index(['class'], 'jig_index')
})

await knex.schema.createTable('berry', t => {
t.text('location').notNullable().primary()
t.text('class')
t.text('scripthash')
t.text('lock')
})

await knex.schema.createTable('trust', t => {
t.text('txid').notNullable().primary()
t.boolean('value').notNullable()
t.index(['txid'], 'trust_txid_index')
})

await knex.schema.createTable('ban', t => {
t.text('txid').notNullable().primary()
t.index(['txid'], 'ban_txid_index')
})

await knex.schema.createTable('tx', t => {
t.text('txid').notNullable().primary()
t.integer('height')
t.timestamp('time')
t.binary('bytes')
t.boolean('has_code')
t.boolean('executable')
t.boolean('executed')
t.boolean('indexed')
t.index(['txid'], 'tx_txid_index')
t.index(['height'], 'tx_height_index')
t.index(['executed', 'txid'], 'tx_executed_index')
})

await knex.schema.createTable('crawl', t => {
t.text('key').unique().notNullable().primary()
t.text('value').notNullable()
})

await knex.schema.createTable('executing', t => {
t.text('txid').notNullable().unique().primary()
})
}

exports.down = async (knex) => {
await knex.schema.dropTable('spends')
await knex.schema.dropTable('deps')
await knex.schema.dropTable('jig')
await knex.schema.dropTable('berry')
await knex.schema.dropTable('trust')
await knex.schema.dropTable('ban')
await knex.schema.dropTable('tx')
await knex.schema.dropTable('crawl')
await knex.schema.dropTable('executing')
}
6 changes: 6 additions & 0 deletions dev/create-dbs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e

psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE DATABASE blobs_regtest;
EOSQL
85 changes: 85 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
version: '3'
services:
# bitcoind:
# image: hojarasca/bitcoinsv-regtest:1.0.10
# volumes:
# - bitcoind-data:/bitcoin/data
# environment:
# RPCUSER: rundb
# RPCPASSWORD: rundb
# ports:
# - 18332:18332
# - 28332:28332

crawler:
build:
context: .
command: ["npm", "run", "start-crawler"]
volumes:
- ./src:/app/src
environment:
MAIN_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/rundb_regtest
BLOB_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/blobs_regtest
RABBITMQ_URI: amqp://guest:guest@rabbitmq:5672
NETWORK: test
BITCOIND_REST_URL: http://bitcoind:18332/rest
ZMQ_URL: tcp://bitcoind:28332
RPC_URL: http://rundb:rundb@bitcoind:18332


execution-worker:
build:
context: .
command: [ "npm", "run", "start-execution-worker" ]
volumes:
- ./src:/app/src
environment:
WORKERS: 1
PORT: 3001
NETWORK: test
MAIN_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/rundb_regtest
BLOB_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/blobs_regtest
RABBITMQ_URI: amqp://guest:guest@rabbitmq:5672

api-server:
build:
context: .
command: [ "npm", "run", "start-api" ]
volumes:
- ./src:/app/src
ports:
- 3000:3000
environment:
PORT: 3000
MAIN_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/rundb_regtest
BLOB_DB_CONNECTION_URI: postgres://someuser:sosecret@psql:5432/blobs_regtest
BITCOIND_REST_URL: http://bitcoind:18332/rest
RABBITMQ_URI: amqp://guest:guest@rabbitmq:5672

psql:
image: postgres:latest
environment:
POSTGRES_USER: someuser
POSTGRES_PASSWORD: sosecret
POSTGRES_DB: rundb_regtest
command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
ports:
- 5432:5432
volumes:
- db-data:/var/lib/postgresql/data
- ./dev/create-dbs.sh:/docker-entrypoint-initdb.d/create-dbs.sh

rabbitmq:
image: rabbitmq:3-management
volumes:
- rabbitmq-data:/var/lib/rabbitmq
# - ./dev/rabbitmq.conf:/etc/rabbitmq/conf.d/10-default-guest-user.conf
ports:
- 5674:5672
- 15674:15672

volumes:
bitcoind-data:
rabbitmq-data:
run-db-data:
db-data:
12 changes: 12 additions & 0 deletions knexfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
client: 'pg',
connection: process.env.DB_CONNECTION_URI || {
user: 'someuser',
password: 'sosecret',
database: 'rundb_regtest'
},
migrations: {
tableName: 'migrations',
directory: 'db-migrations'
}
}
Loading

0 comments on commit f2f70b4

Please sign in to comment.