From eedf802bf9cb6bdbbfa4a52802406a68be14f553 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:06:25 -0700 Subject: [PATCH 01/10] Run sever command --- deploy/ord.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/ord.service b/deploy/ord.service index a77ec04fb4..71a5f113d9 100644 --- a/deploy/ord.service +++ b/deploy/ord.service @@ -11,7 +11,7 @@ ExecStart=/usr/local/bin/ord \ --index-size 1TiB \ --rpc-url 127.0.0.1:8332 \ --cookie-file /var/lib/bitcoind/.cookie \ - index + server # Process management #################### From 145437ccdbcf64765b002283a1cfc2642d8856d7 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:08:25 -0700 Subject: [PATCH 02/10] allow configuring deploy branch --- deploy/checkout | 6 ++++-- justfile | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/deploy/checkout b/deploy/checkout index 47a773554c..2b2aedf7ae 100755 --- a/deploy/checkout +++ b/deploy/checkout @@ -2,6 +2,8 @@ set -euxo pipefail +branch=$1 + if [[ ! -d ord ]]; then git clone https://github.com/casey/ord.git fi @@ -9,6 +11,6 @@ fi cd ord git fetch origin -git checkout -B master -git reset --hard origin/master +git checkout -B $1 +git reset --hard origin/$1 ./deploy/setup diff --git a/justfile b/justfile index 8728e8e723..d89f0c2238 100644 --- a/justfile +++ b/justfile @@ -24,10 +24,10 @@ watch +args='ltest': install-dev-deps: cargo install cargo-criterion -deploy: +deploy branch='master': ssh root@65.108.68.37 mkdir -p deploy rsync -avz deploy/checkout root@65.108.68.37:deploy/checkout - ssh root@65.108.68.37 'cd deploy && ./checkout' + ssh root@65.108.68.37 'cd deploy && ./checkout {{branch}}' status: ssh root@65.108.68.37 systemctl status bitcoind From 81839b70dd09581ab7768f0b7a65deedd08361fb Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:15:31 -0700 Subject: [PATCH 03/10] stop ord before overwriting binary --- deploy/setup | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy/setup b/deploy/setup index a28ca6f3e9..8633227eab 100755 --- a/deploy/setup +++ b/deploy/setup @@ -15,7 +15,6 @@ fi source ~/.cargo/env cargo build --release -cp target/release/ord /usr/local/bin/ord id --user bitcoin || useradd --system bitcoin id --user ord || useradd --system ord @@ -31,5 +30,7 @@ setfacl -m ord:r /var/lib/bitcoind/.cookie cp deploy/ord.service /etc/systemd/system/ systemctl daemon-reload +systemctl stop ord +cp target/release/ord /usr/local/bin/ord systemctl enable ord systemctl restart ord From d799553b4856f3cf3ea41da7b59c9185d222d91d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:22:50 -0700 Subject: [PATCH 04/10] Turn on backtraces --- Cargo.toml | 2 +- deploy/ord.service | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2d3c1064a3..acd82ca4fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ edition = "2021" autotests = false [dependencies] -anyhow = "1.0.56" +anyhow = { version = "1.0.56", features = ["backtrace"] } axum = "0.4.8" axum-server = "0.3.3" bitcoin = "0.27.1" diff --git a/deploy/ord.service b/deploy/ord.service index 71a5f113d9..fb69b802c6 100644 --- a/deploy/ord.service +++ b/deploy/ord.service @@ -6,6 +6,7 @@ StartLimitIntervalSec=10m [Service] WorkingDirectory=/var/lib/ord +Environment="RUST_BACKTRACE=1" Environment="RUST_LOG=info" ExecStart=/usr/local/bin/ord \ --index-size 1TiB \ From 519348418890f2c5dfa6390b8b6943abae8efd0d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:23:17 -0700 Subject: [PATCH 05/10] Update lockfile --- Cargo.lock | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3387206ed2..7586cbc572 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,21 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + [[package]] name = "aho-corasick" version = "0.7.18" @@ -16,6 +31,9 @@ name = "anyhow" version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27" +dependencies = [ + "backtrace", +] [[package]] name = "async-trait" @@ -104,6 +122,21 @@ dependencies = [ "tower-service", ] +[[package]] +name = "backtrace" +version = "0.3.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e121dee8023ce33ab248d9ce1493df03c3b38a659b240096fcbd7048ff9c31f" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.0" @@ -660,6 +693,12 @@ dependencies = [ "wasi 0.10.0+wasi-snapshot-preview1", ] +[[package]] +name = "gimli" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" + [[package]] name = "globset" version = "0.4.8" @@ -1089,6 +1128,16 @@ version = "0.3.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" +[[package]] +name = "miniz_oxide" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" +dependencies = [ + "adler", + "autocfg", +] + [[package]] name = "mio" version = "0.8.2" @@ -1192,6 +1241,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.27.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.10.0" @@ -1630,6 +1688,12 @@ dependencies = [ "winreg", ] +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + [[package]] name = "rustc_version" version = "0.4.0" From 7a17f861823f6dd565d8362889d82c54aaa8e832 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:25:42 -0700 Subject: [PATCH 06/10] Print backtraces --- deploy/ord.service | 4 ++-- src/main.rs | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/deploy/ord.service b/deploy/ord.service index fb69b802c6..22a10dd2ce 100644 --- a/deploy/ord.service +++ b/deploy/ord.service @@ -6,8 +6,8 @@ StartLimitIntervalSec=10m [Service] WorkingDirectory=/var/lib/ord -Environment="RUST_BACKTRACE=1" -Environment="RUST_LOG=info" +Environment=RUST_BACKTRACE=1 +Environment=RUST_LOG=info ExecStart=/usr/local/bin/ord \ --index-size 1TiB \ --rpc-url 127.0.0.1:8332 \ diff --git a/src/main.rs b/src/main.rs index 2485e45ca1..693d4912e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -86,6 +86,7 @@ fn main() { if let Err(error) = Arguments::parse().run() { eprintln!("error: {}", error); + eprintln!("{}", error.backtrace()); process::exit(1); } } From 74eb99948506cb03d67a96cc012fcf559f06ecbb Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:31:14 -0700 Subject: [PATCH 07/10] Listen on socket 8000 --- deploy/ord.service | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy/ord.service b/deploy/ord.service index 22a10dd2ce..b5bb54419b 100644 --- a/deploy/ord.service +++ b/deploy/ord.service @@ -12,7 +12,8 @@ ExecStart=/usr/local/bin/ord \ --index-size 1TiB \ --rpc-url 127.0.0.1:8332 \ --cookie-file /var/lib/bitcoind/.cookie \ - server + server \ + --port 8000 # Process management #################### From 2f3789039cd2f2e661573da39511057b6bf468b6 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:37:29 -0700 Subject: [PATCH 08/10] Only print backtrace if enabled --- src/main.rs | 5 ++++- tests/integration.rs | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 693d4912e2..e8813b8070 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ use { cell::Cell, cmp::Ordering, collections::VecDeque, + env, fmt::{self, Display, Formatter}, io, net::ToSocketAddrs, @@ -86,7 +87,9 @@ fn main() { if let Err(error) = Arguments::parse().run() { eprintln!("error: {}", error); - eprintln!("{}", error.backtrace()); + if env::var_os("RUST_BACKTRACE") == Some("1".into()) { + eprintln!("{}", error.backtrace()); + } process::exit(1); } } diff --git a/tests/integration.rs b/tests/integration.rs index 8f3c202631..ce292c4039 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -17,7 +17,7 @@ use { process::{Command, Stdio}, str, sync::{Arc, Mutex}, - thread::{self, sleep}, + thread, time::{Duration, Instant}, }, tempfile::TempDir, @@ -211,7 +211,7 @@ impl Test { break; } - sleep(Duration::from_millis(100)); + thread::sleep(Duration::from_millis(100)); } if healthy { From 8e011b61daba8c41220f9fe5e135113ea70b39a0 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:41:42 -0700 Subject: [PATCH 09/10] Tweak --- src/index.rs | 2 +- src/main.rs | 1 + tests/integration.rs | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.rs b/src/index.rs index fde9599318..4087cbda0e 100644 --- a/src/index.rs +++ b/src/index.rs @@ -52,7 +52,7 @@ impl Index { let sleep_until = self.sleep_until.get(); if sleep_until > now { - std::thread::sleep(sleep_until - now); + thread::sleep(sleep_until - now); } self diff --git a/src/main.rs b/src/main.rs index e8813b8070..5d7bf03ad3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,7 @@ use { atomic::{self, AtomicU64}, Arc, Mutex, }, + thread, time::{Duration, Instant}, }, tokio::runtime::Runtime, diff --git a/tests/integration.rs b/tests/integration.rs index ce292c4039..8f3c202631 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -17,7 +17,7 @@ use { process::{Command, Stdio}, str, sync::{Arc, Mutex}, - thread, + thread::{self, sleep}, time::{Duration, Instant}, }, tempfile::TempDir, @@ -211,7 +211,7 @@ impl Test { break; } - thread::sleep(Duration::from_millis(100)); + sleep(Duration::from_millis(100)); } if healthy { From 3d869e90099745e6a52ea70be4bb88ed642c3fdd Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 21 Mar 2022 15:44:31 -0700 Subject: [PATCH 10/10] tweak --- src/main.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 5d7bf03ad3..970597c113 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,10 @@ fn main() { if let Err(error) = Arguments::parse().run() { eprintln!("error: {}", error); - if env::var_os("RUST_BACKTRACE") == Some("1".into()) { + if env::var_os("RUST_BACKTRACE") + .map(|val| val == "1") + .unwrap_or_default() + { eprintln!("{}", error.backtrace()); } process::exit(1);