Skip to content

Commit

Permalink
something like a spot bitcoind
Browse files Browse the repository at this point in the history
  • Loading branch information
0xFlicker committed Jan 15, 2024
1 parent 4348c7c commit 50e9c6d
Show file tree
Hide file tree
Showing 14 changed files with 443 additions and 158 deletions.
6 changes: 6 additions & 0 deletions .sops.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
creation_rules:
- path_regex: secrets/testnet/.*
key_groups:
- kms:
- arn: arn:aws:kms:us-east-2:167146046754:key/42d63d0c-0f8e-493f-ac73-91c83da1341e
role: arn:aws:iam::167146046754:role/sopsAdmin
Binary file not shown.
31 changes: 31 additions & 0 deletions deploy/bitcoin/config.sh.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

NODE_ARCHIVE={{node_archive}}
NODE_FOLDER=dirname $NODE_ARCHIVE
BITCOIN_ARCHIVE={{bitcoin_archive}}
BITCOIN_FOLDER=dirname $BITCOIN_ARCHIVE
DATA_DIR_S3={{data_dir_s3}}
DATA_DIR={{data_dir}}
BLOCKCHAIN_DATA={{blockchain_data}}

# extract node
cd $NODE_FOLDER
tar xzf $NODE_ARCHIVE
rm $NODE_ARCHIVE
mv node*/bin/* /usr/local/bin
rm -rf node-*

# extract bitcoin
cd $BITCOIN_FOLDER
tar xzf $BITCOIN_ARCHIVE
rm $BITCOIN_ARCHIVE
mv bitcoin*/bin/* /usr/local/bin
rm -rf bitcoin-*

# extract data dir and conf from s3
mkdir -p $DATA_DIR
cd $DATA_DIR
aws s3 cp $DATA_DIR_S3 - | tar xzf -

# assign ownership to ec2-user
chown -R ec2-user:ec2-user $BLOCKCHAIN_DATA
Binary file added deploy/bitcoin/node-v20.9.0-linux-arm64.tar.xz
Binary file not shown.
11 changes: 11 additions & 0 deletions deploy/bitcoin/testnet/bitcoin.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[test]
rpcauth=electrs:3708e5d4c661a81c04e11bdb68b0ab55\$2e18fd00dacecda9dc0e7319fa4acd0539c920060a2742b8c20d333f718fbfe5
rpcauth=mempool:b65c2dd205f239ce8e4ed93f1a199038\$087d593c514a8ed314a7473a9720a23cfdbba4838e15e3b48c102771620c48a2
rpcauth=admin:09154d35c305b13efa3874c393c3287f\$eb29e024b68fd1a54c830da7381f52d71f60eda5637f012fef912104e47ccfb9
datadir=/dev/xvda/bitcoin
txindex=1
prune=0
server=1
rpcallowip={{rpcallowip}}
rpcbind=127.0.0.1
debug=rpc
23 changes: 23 additions & 0 deletions deploy/bitcoin/testnet/cloudwatch.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"agent": {
"run_as_user": "root"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/home/ec2-user/bitcoin.stderr.log",
"log_group_name": "bitcoin-testnet-stderr-log",
"log_stream_name": "{instance_id}"
},
{
"file_path": "/home/ec2-user/bitcoin.stdout.log",
"log_group_name": "bitcoin-testnet-stdout-log",
"log_stream_name": "{instance_id}"
}
]
}
}
}
}
28 changes: 28 additions & 0 deletions deploy/bitcoin/testnet/healthcheck.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { createServer } from 'http';
import { spawn } from 'child_process';

async function checkBitcoin() {
return new Promise((resolve, reject) => {
const bitcoin = spawn('bitcoin-cli', ['-testnet', '-datadir=/home/ec2-user/.bitcoin', 'getblockchaininfo']);
bitcoin.on('close', (code) => {
if (code === 0) {
resolve(void 0);
} else {
reject();
}
});
});
}

const server = createServer(async (_, res) => {
try {
await checkBitcoin();
res.writeHead(200);
res.end();
} catch (e) {
res.writeHead(500);
res.end();
}
});

server.listen(8080);
5 changes: 3 additions & 2 deletions deploy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
"deploy": "cdk deploy"
},
"dependencies": {
"aws-cdk-lib": "^2.85.0",
"cdk": "^2.85.0",
"aws-cdk-lib": "^2.121.1",
"cdk": "^2.121.1",
"construct": "^1.0.0",
"constructs": "^10.2.57",
"handlebars": "^4.7.8"
},
Expand Down
8 changes: 8 additions & 0 deletions deploy/scripts/uploadBlockchainData.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

DATA_DIR=$1
BUCKET_NAME=$2
NETWORK=$3

cd "$DATA_DIR"
tar -czvf - * | aws s3 cp --only-show-errors - s3://$BUCKET_NAME/$NETWORK.tar.gz
Loading

0 comments on commit 50e9c6d

Please sign in to comment.