Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config all #3188

Merged
merged 11 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,22 +216,22 @@ Alternatively, `ord` can be supplied with a username and password on the
command line:

```
ord --bitcoin-rpc-user foo --bitcoin-rpc-pass bar server
ord --bitcoin-rpc-username foo --bitcoin-rpc-password bar server
```

Using environment variables:

```
export ORD_BITCOIN_RPC_USER=foo
export ORD_BITCOIN_RPC_PASS=bar
export ORD_BITCOIN_RPC_USERNAME=foo
export ORD_BITCOIN_RPC_PASSWORD=bar
ord server
```

Or in the config file:

```yaml
bitcoin_rpc_user: foo
bitcoin_rpc_pass: bar
bitcoin_rpc_username: foo
bitcoin_rpc_password: bar
```

Logging
Expand Down
2 changes: 1 addition & 1 deletion docs/src/guides/sat-hunting.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ wallet is named `foo`:
2. Display any rare ordinals wallet `foo`'s UTXOs:

```sh
ord --wallet foo --index-sats wallet sats
ord --index-sats wallet --name foo sats
```

### Searching for Rare Ordinals in a Non-Bitcoin Core Wallet
Expand Down
53 changes: 37 additions & 16 deletions docs/src/guides/settings.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
Settings
========

`ord` can be configured with command line options, environment variables, a
`ord` can be configured with the command line, environment variables, a
configuration file, and default values.

When multiple sources configure the same thing, precedence is in order of
command line options, then environment variables, then the configuration file,
and finally default values.
The command line takes precedence over environment variables, which take
precedence over the configuration file, which takes precedence over defaults.

The path to the configuration can be given with `--config <CONFIG_PATH>`. `ord`
will error if `<CONFIG_PATH>` doesn't exist. The path to a configuration
The path to the configuration file can be given with `--config <CONFIG_PATH>`.
`ord` will error if `<CONFIG_PATH>` doesn't exist. The path to a configuration
directory can be given with `--config-dir <CONFIG_DIR_PATH>`, in which case the
config path is `<CONFIG_DIR_PATH>/ord.yaml`. It is not an error if
`<CONFIG_DIR_PATH>/ord.yaml` does not exist, and `ord` will use a configuration
with default values.
`<CONFIG_DIR_PATH>/ord.yaml` does not exist.

All settings can be configured with command line options, but not all settings
can yet be configured with environmnet variables or a configuration file.
For a setting named `--setting-name` on the command line, the environment
variable will be named `ORD_SETTING_NAME`, and the config file field will be
named `setting_name`. For example, the data directory can be configured with
`--data-dir` on the command line, the `ORD_DATA_DIR` environment variable, or
`data_dir` in the config file.

`ord`'s configuration can be viewd as JSON with `ord settings`.
See `ord --help` for documentation of all the settings.

| setting | CLI | environment variable | default value |
| --- | --- | --- | --- |
| bitcoin RPC password | `--bitcoin-rpc-pass <PASSWORD>` | `ORD_BITCOIN_RPC_PASS` | none |
| bitcoin RPC username | `--bitcoin-rpc-user <USERNAME>` | `ORD_BITCOIN_RPC_USER` | none |
| chain | `--chain <CHAIN>` | `ORD_CHAIN` | mainnet |
`ord`'s current configuration can be viewed as JSON with the `ord settings`
command.

Hiding Inscription Content
--------------------------

Inscription content can be selectively prevented from being served by `ord
server`.

Unlike other settings, this can only be configured with the configuration file
or environment variables.

To hide inscriptions with an environment variable:

```
export ORD_HIDDEN='6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0'
```

Or with the configuration file:

```yaml
hidden:
- 6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0
- 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0
```
29 changes: 22 additions & 7 deletions ord.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
# Example Config
# example config

chain: mainnet

# use username `bar` and password `foo` for bitcoind RPC calls
bitcoin_rpc_user: bar
bitcoin_rpc_pass: foo
# see `ord --help` for setting documentation

# prevent `ord server` from serving the content of the inscriptions below
bitcoin_data_dir: /var/lib/bitcoin
bitcoin_rpc_password: bar
bitcoin_rpc_url: https://localhost:8000
bitcoin_rpc_username: foo
chain: mainnet
commit_interval: 10000
cookie_file: /var/lib/bitcoin/.cookie
data_dir: /var/lib/ord
first_inscription_height: 100
height_limit: 1000
hidden:
- 6fb976ab49dcec017f1e201e84395983204ae1a7c2abf7ced0a85d692e442799i0
- 703e5f7c49d82aab99e605af306b9a30e991e57d42f982908a962a81ac439832i0
index: /var/lib/ord/index.redb
index_cache_size: 1000000000
index_runes: true
index_sats: true
index_spent_sats: true
index_transactions: true
integration_test: true
no_index_inscriptions: true
server_password: bar
server_username: foo
6 changes: 1 addition & 5 deletions src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ impl Arguments {
);
}

let config = self.options.config()?;

self
.subcommand
.run(Settings::new(self.options, env, config)?)
self.subcommand.run(Settings::load(self.options)?)
}
}
10 changes: 5 additions & 5 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl Chain {
Address::from_script(script, self.network())
}

pub(crate) fn join_with_data_dir(self, data_dir: &Path) -> PathBuf {
pub(crate) fn join_with_data_dir(self, data_dir: impl AsRef<Path>) -> PathBuf {
match self {
Self::Mainnet => data_dir.to_owned(),
Self::Testnet => data_dir.join("testnet3"),
Self::Signet => data_dir.join("signet"),
Self::Regtest => data_dir.join("regtest"),
Self::Mainnet => data_dir.as_ref().to_owned(),
Self::Testnet => data_dir.as_ref().join("testnet3"),
Self::Signet => data_dir.as_ref().join("signet"),
Self::Regtest => data_dir.as_ref().join("regtest"),
}
}
}
Expand Down
20 changes: 0 additions & 20 deletions src/config.rs

This file was deleted.

32 changes: 11 additions & 21 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ impl Index {
) -> Result<Self> {
let client = settings.bitcoin_rpc_client(None)?;

let path = settings
.index
.clone()
.unwrap_or_else(|| settings.data_dir().clone().join("index.redb"));
let path = settings.index().to_owned();

if let Err(err) = fs::create_dir_all(path.parent().unwrap()) {
bail!(
Expand All @@ -242,16 +239,9 @@ impl Index {
);
}

let db_cache_size = match settings.db_cache_size {
Some(db_cache_size) => db_cache_size,
None => {
let mut sys = System::new();
sys.refresh_memory();
usize::try_from(sys.total_memory() / 4)?
}
};
let index_cache_size = settings.index_cache_size();

log::info!("Setting DB cache size to {} bytes", db_cache_size);
log::info!("Setting index cache size to {} bytes", index_cache_size);

let durability = if cfg!(test) {
redb::Durability::None
Expand All @@ -262,7 +252,7 @@ impl Index {
let index_path = path.clone();
let once = Once::new();
let progress_bar = Mutex::new(None);
let integration_test = settings.integration_test;
let integration_test = settings.integration_test();

let repair_callback = move |progress: &mut RepairSession| {
once.call_once(|| println!("Index file `{}` needs recovery. This can take a long time, especially for the --index-sats index.", index_path.display()));
Expand All @@ -284,7 +274,7 @@ impl Index {
};

let database = match Database::builder()
.set_cache_size(db_cache_size)
.set_cache_size(index_cache_size)
.set_repair_callback(repair_callback)
.open(&path)
{
Expand Down Expand Up @@ -319,7 +309,7 @@ impl Index {
if error.kind() == io::ErrorKind::NotFound =>
{
let database = Database::builder()
.set_cache_size(db_cache_size)
.set_cache_size(index_cache_size)
.create(&path)?;

let mut tx = database.begin_write()?;
Expand Down Expand Up @@ -350,7 +340,7 @@ impl Index {
let mut outpoint_to_sat_ranges = tx.open_table(OUTPOINT_TO_SAT_RANGES)?;
let mut statistics = tx.open_table(STATISTIC_TO_COUNT)?;

if settings.index_sats {
if settings.index_sats() {
outpoint_to_sat_ranges.insert(&OutPoint::null().store(), [].as_slice())?;
}

Expand All @@ -363,19 +353,19 @@ impl Index {
Self::set_statistic(
&mut statistics,
Statistic::IndexSats,
u64::from(settings.index_sats || settings.index_spent_sats),
u64::from(settings.index_sats() || settings.index_spent_sats()),
)?;

Self::set_statistic(
&mut statistics,
Statistic::IndexSpentSats,
u64::from(settings.index_spent_sats),
u64::from(settings.index_spent_sats()),
)?;

Self::set_statistic(
&mut statistics,
Statistic::IndexTransactions,
u64::from(settings.index_transactions),
u64::from(settings.index_transactions()),
)?;

Self::set_statistic(&mut statistics, Statistic::Schema, SCHEMA_VERSION)?;
Expand Down Expand Up @@ -413,7 +403,7 @@ impl Index {
event_sender,
first_inscription_height: settings.first_inscription_height(),
genesis_block_coinbase_transaction,
height_limit: settings.height_limit,
height_limit: settings.height_limit(),
index_runes,
index_sats,
index_spent_sats,
Expand Down
8 changes: 4 additions & 4 deletions src/index/fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl Fetcher {
pub(crate) fn new(settings: &Settings) -> Result<Self> {
let client = Client::new();

let url = if settings.rpc_url(None).starts_with("http://") {
settings.rpc_url(None)
let url = if settings.bitcoin_rpc_url(None).starts_with("http://") {
settings.bitcoin_rpc_url(None)
} else {
"http://".to_string() + &settings.rpc_url(None)
"http://".to_string() + &settings.bitcoin_rpc_url(None)
};

let url = Uri::try_from(&url).map_err(|e| anyhow!("Invalid rpc url {url}: {e}"))?;

let (user, password) = settings.auth()?.get_user_pass()?;
let (user, password) = settings.bitcoin_credentials()?.get_user_pass()?;
let auth = format!("{}:{}", user.unwrap(), password.unwrap());
let auth = format!(
"Basic {}",
Expand Down
7 changes: 5 additions & 2 deletions src/index/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl ContextBuilder {

let command: Vec<OsString> = vec![
"ord".into(),
"--rpc-url".into(),
"--bitcoin-rpc-url".into(),
rpc_server.url().into(),
"--data-dir".into(),
tempdir.path().into(),
Expand All @@ -33,7 +33,10 @@ impl ContextBuilder {
];

let options = Options::try_parse_from(command.into_iter().chain(self.args)).unwrap();
let index = Index::open_with_event_sender(&options.settings().unwrap(), self.event_sender)?;
let index = Index::open_with_event_sender(
&Settings::from_options(options).or_defaults().unwrap(),
self.event_sender,
)?;
index.update().unwrap();

Ok(Context {
Expand Down
6 changes: 3 additions & 3 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'index> Updater<'index> {
let mut progress_bar = if cfg!(test)
|| log_enabled!(log::Level::Info)
|| starting_height <= self.height
|| self.index.settings.integration_test
|| self.index.settings.integration_test()
{
None
} else {
Expand Down Expand Up @@ -98,7 +98,7 @@ impl<'index> Updater<'index> {

uncommitted += 1;

if uncommitted == self.index.settings.commit_interval {
if uncommitted == self.index.settings.commit_interval() {
self.commit(wtx, value_cache)?;
value_cache = HashMap::new();
uncommitted = 0;
Expand Down Expand Up @@ -326,7 +326,7 @@ impl<'index> Updater<'index> {
let mut outpoint_to_value = wtx.open_table(OUTPOINT_TO_VALUE)?;

let index_inscriptions = self.height >= self.index.first_inscription_height
&& !self.index.settings.no_index_inscriptions;
&& self.index.settings.index_inscriptions();

if index_inscriptions {
// Send all missing input outpoints to be fetched right away
Expand Down
2 changes: 1 addition & 1 deletion src/inscriptions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use self::{envelope::Envelope, inscription::Inscription, inscription_id::Ins
mod charm;
mod envelope;
mod inscription;
mod inscription_id;
pub(crate) mod inscription_id;
pub(crate) mod media;
mod tag;
pub(crate) mod teleburn;
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use {
self::{
arguments::Arguments,
blocktime::Blocktime,
config::Config,
decimal::Decimal,
inscriptions::{
inscription_id,
media::{self, ImageRendering, Media},
teleburn, Charm, ParsedEnvelope,
},
Expand Down Expand Up @@ -107,7 +107,6 @@ pub mod api;
pub mod arguments;
mod blocktime;
pub mod chain;
mod config;
mod decimal;
mod fee_rate;
pub mod index;
Expand Down Expand Up @@ -186,7 +185,7 @@ pub fn parse_ord_server_args(args: &str) -> (Settings, subcommand::server::Serve
match Arguments::try_parse_from(args.split_whitespace()) {
Ok(arguments) => match arguments.subcommand {
Subcommand::Server(server) => (
Settings::new(
Settings::merge(
arguments.options,
vec![("INTEGRATION_TEST".into(), "1".into())]
.into_iter()
Expand Down
Loading
Loading