Skip to content

Commit

Permalink
Add regtest support. (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvc94ch authored Nov 1, 2022
1 parent 23e92f3 commit 6f7a209
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ run-mainnet-offline:
docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=MAINNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest

run-testnet-online:
docker run -d --rm --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 rosetta-bitcoin:latest
docker run -d --rm --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=TESTNET" -e "PORT=8080" -p 8080:8080 -p 18333:18333 -p 18332:18332 rosetta-bitcoin:latest

run-testnet-offline:
docker run -d --rm -e "MODE=OFFLINE" -e "NETWORK=TESTNET" -e "PORT=8081" -p 8081:8081 rosetta-bitcoin:latest

run-regtest-online:
docker run -d --rm --ulimit "nofile=${NOFILE}:${NOFILE}" -v "${PWD}/bitcoin-data:/data" -e "MODE=ONLINE" -e "NETWORK=REGTEST" -e "PORT=8080" -p 8080:8080 -p 18333:18333 -p 18443:18443 rosetta-bitcoin:latest

train:
./zstd-train.sh $(network) transaction $(data-directory)

Expand Down
29 changes: 29 additions & 0 deletions assets/bitcoin-regtest.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
##
## bitcoin.conf configuration file. Lines beginning with # are comments.
##

# DO NOT USE THIS CONFIGURATION FILE IF YOU PLAN TO EXPOSE
# BITCOIND'S RPC PORT PUBLICALLY (THESE INSECURE CREDENTIALS
# COULD LEAD TO AN ATTACK). ROSETTA-BITCOIN USES THE RPC PORT
# FOR INDEXING AND TRANSACTION BROADCAST BUT NEVER PROVIDES THE
# CALLER ACCESS TO BITCOIND'S RPC PORT.

datadir=/data/bitcoind
bantime=15
rpcallowip=0.0.0.0/0
rpcthreads=16
rpcworkqueue=1000
disablewallet=1
txindex=0
rpcuser=rosetta
rpcpassword=rosetta

# allow manual pruning
prune=1
regtest=1

[regtest]
port=18333
bind=0.0.0.0
rpcport=18443
rpcbind=0.0.0.0
7 changes: 7 additions & 0 deletions bitcoin/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const (
// in TestnetNetworkIdentifier.
TestnetNetwork string = "Testnet3"

// RegtestNetwork is the value of the network
// in RegtestNetworkIdentifier.
RegtestNetwork string = "Regtest"

// Decimals is the decimals value
// used in Currency.
Decimals = 8
Expand Down Expand Up @@ -108,6 +112,9 @@ var (
// TestnetParams are the params for testnet.
TestnetParams = &chaincfg.TestNet3Params

// RegtestParams are the params for regtest.
RegtestParams = &chaincfg.RegressionNetParams

// TestnetCurrency is the *types.Currency for testnet.
TestnetCurrency = &types.Currency{
Symbol: "tBTC",
Expand Down
24 changes: 24 additions & 0 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const (
// Testnet is Bitcoin Testnet3.
Testnet string = "TESTNET"

// Regtest is Bitcoin Regtest
Regtest string = "REGTEST"

// mainnetConfigPath is the path of the Bitcoin
// configuration file for mainnet.
mainnetConfigPath = "/app/bitcoin-mainnet.conf"
Expand All @@ -56,13 +59,18 @@ const (
// configuration file for testnet.
testnetConfigPath = "/app/bitcoin-testnet.conf"

// regtestConfigPath is the path of the Bitcoin
// configuration file for testnet.
regtestConfigPath = "/app/bitcoin-regtest.conf"

// Zstandard compression dictionaries
transactionNamespace = "transaction"
testnetTransactionDictionary = "/app/testnet-transaction.zstd"
mainnetTransactionDictionary = "/app/mainnet-transaction.zstd"

mainnetRPCPort = 8332
testnetRPCPort = 18332
regtestRPCPort = 18443

// min prune depth is 288:
// https://github.com/bitcoin/bitcoin/blob/ad2952d17a2af419a04256b10b53c7377f826a27/src/validation.h#L84
Expand Down Expand Up @@ -189,6 +197,22 @@ func LoadConfiguration(baseDirectory string) (*Configuration, error) {
DictionaryPath: testnetTransactionDictionary,
},
}
case Regtest:
config.Network = &types.NetworkIdentifier{
Blockchain: bitcoin.Blockchain,
Network: bitcoin.RegtestNetwork,
}
config.GenesisBlockIdentifier = bitcoin.TestnetGenesisBlockIdentifier
config.Params = bitcoin.RegtestParams
config.Currency = bitcoin.TestnetCurrency
config.ConfigPath = regtestConfigPath
config.RPCPort = regtestRPCPort
config.Compressors = []*encoder.CompressorEntry{
{
Namespace: transactionNamespace,
DictionaryPath: testnetTransactionDictionary,
},
}
case "":
return nil, errors.New("NETWORK must be populated")
default:
Expand Down

0 comments on commit 6f7a209

Please sign in to comment.