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

feat: jubilee support #235

Closed
wants to merge 107 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
9855b77
chore: cargo fmt
Nov 2, 2023
f9e2ac4
fix: making db access more defensive
Nov 2, 2023
b101de5
chore: clippy
Nov 2, 2023
d1b5d68
fix: reopen conn on each iteration
Nov 3, 2023
319d956
fix: retry mechanism for statement prepare
Nov 3, 2023
6704a2b
refactor: sqlite requests retries
Nov 3, 2023
fa05163
feat: set explicit timeout value
Nov 3, 2023
4eed91a
fix: make logging optional
Nov 4, 2023
f5f1c33
chore: logger cleaning
Nov 4, 2023
4b5e9c4
fix: result looping
Nov 7, 2023
67a8943
feat: introduce ORDHOOK_MAINTENANCE mode, revisit cli options
Nov 14, 2023
c619fec
chore: re-qualify logs
Nov 14, 2023
f70fdba
chore: enable mode code site
Nov 14, 2023
04e13b9
chore: re-qualify log
Nov 14, 2023
76e6ed1
fix: keep trying opening conn
Nov 14, 2023
d65cc22
fix: improve rocksdb resiliency with retries
Nov 16, 2023
ff285e7
fix: baseline experiment
Nov 16, 2023
b39472f
chore: update chainhook-sdk
Nov 16, 2023
78cee50
fix: testnet support
Nov 17, 2023
6f5bd3d
Squashed commit of the following:
Nov 27, 2023
13faa1c
chore: update Cargo.lock
Nov 27, 2023
ea5cba6
chore: cargo fmt
Nov 27, 2023
8464d0d
Merge branch 'develop' into fix/database-optims
Nov 27, 2023
308b7f2
fix: merge artifact
Nov 27, 2023
8d21f39
Merge branch 'develop' into fix/database-optims
Nov 28, 2023
38bead9
fix: rocksdb fine tuning
Nov 28, 2023
c4bad08
fix: Cargo.toml warns
Nov 28, 2023
4410933
feat: auto-repair at boot
Nov 28, 2023
568a6c8
fix: rocksdb conn handling
Nov 28, 2023
638d3f7
fix: improve backoff strategy
Nov 28, 2023
413251e
Merge branch 'fix/database-optims' of github.com:hirosystems/hord int…
Nov 28, 2023
91dfc02
chore: refactor BlockBytesCursor usage
Nov 28, 2023
e1741a8
fix: update sequence_metadata when augmenting block
Nov 29, 2023
9b1a905
feat: revisit observers handling
Nov 30, 2023
5924097
fix: aborted loop
Nov 30, 2023
2584bfb
Merge branch 'fix/database-optims' of github.com:hirosystems/hord int…
Nov 30, 2023
ef6b060
fix: stateful observers
Dec 1, 2023
2d78c8c
fix: build warnings
Dec 1, 2023
0b476b5
chore: tweak db config
Dec 13, 2023
cc4f89b
fix: include coinbase output offset
Dec 13, 2023
ddbe675
chore: tweak cli
Dec 13, 2023
bdd1dda
fix: iterator usage
Dec 13, 2023
7520b42
chore: disable blobdb
Dec 14, 2023
3015e28
fix: broken test
Dec 15, 2023
4430922
Merge pull request #230 from hirosystems/fix/coinbase-outputs
Dec 18, 2023
a2823de
Merge branch 'develop' into fix/database-optims
Dec 18, 2023
e1415ec
chore: update dependencies
Dec 18, 2023
8d2ab05
chore: augment db schema
Dec 22, 2023
fd295a0
chore: update ord
Dec 22, 2023
08e31a6
chore: inscription parsing re-integration
Dec 23, 2023
e36d38a
feat: persist inscription_subindex
Dec 26, 2023
e82ba4b
feat: update sequence_metadata
Dec 26, 2023
1fd92e2
fix: sql field name
Dec 26, 2023
1b18f9e
fix: build warnings
Dec 26, 2023
3645032
chore: update chainhook sdk
Dec 26, 2023
e6cbd59
Merge branch 'develop' into feat/jubilee-support
Jan 2, 2024
bbb208a
fix: indexing subindex
Jan 3, 2024
b4483d9
Merge branch 'feat/jubilee-support' of github.com:hirosystems/ordhook…
Jan 3, 2024
69aab97
fix: tx chaining reinscription handling
Jan 3, 2024
3e905c1
chore: add missing indexes
Jan 3, 2024
d98b55d
chore: restore set_max_open_files
Jan 3, 2024
c3be152
fix: dockerfile
Jan 3, 2024
6540d6b
feat: panic when unable to retrieve ordinal number
Jan 3, 2024
761c94a
chore: disable integrity check for now
Jan 4, 2024
3904057
chore: exit process on error
Jan 4, 2024
d7a986f
fix: attempt to fix race condition
Jan 4, 2024
d6999e7
chore: disable cache tmp
Jan 4, 2024
cfa75ab
fix: patch traversals can be reused
Jan 4, 2024
41ecf76
fix: patch traversals can be reused
Jan 4, 2024
9e4ba72
chore: fix expectations
Jan 4, 2024
9ade8f3
fix: replay
Jan 4, 2024
d75769c
fix: replay + jubilee number increment
Jan 5, 2024
85bbbcb
feat: revisit config files
Jan 11, 2024
ca8f439
fix: handle inscription pointers
Jan 11, 2024
b1286e8
feat: locations are now ordinal_number centric (instead of inscriptio…
Jan 11, 2024
b7fc2c3
Merge branch 'develop' into feat/jubilee-support
Jan 11, 2024
5292875
Merge branch 'feat/jubilee-support' of github.com:hirosystems/ordhook…
Jan 11, 2024
fd73567
feat: improve queue management
lgalabru Jan 12, 2024
2377295
fix: ordinal_number data type
lgalabru Jan 12, 2024
40ed3b7
fix: disable mmap reads
lgalabru Jan 16, 2024
21846c1
feat: migrate to jemallocator
lgalabru Jan 16, 2024
1d6cb6d
feat: migrate to tcmalloc
lgalabru Jan 16, 2024
7fc5da9
fix: align libunwind8
lgalabru Jan 16, 2024
6543b1e
chore: simplify image
lgalabru Jan 16, 2024
15a55ad
chore: restore multi-stage image
lgalabru Jan 18, 2024
c7a53fa
fix: pointer ignored
lgalabru Jan 23, 2024
c067883
feat: extract additional data
lgalabru Jan 25, 2024
b888723
fix: simulate ord numbering bug
lgalabru Jan 25, 2024
11ebd64
chore: remove broken tests
lgalabru Jan 25, 2024
73ced15
fix: additional adjustments on pointers
lgalabru Jan 31, 2024
b54ffd9
fix: tests
lgalabru Jan 31, 2024
38aa388
Merge branch 'develop' into feat/jubilee-support
Feb 1, 2024
1b61070
fix: build
lgalabru Feb 1, 2024
3c11c83
fix: jubilee increment
lgalabru Feb 2, 2024
4e3af19
fix: satoshis computations duplicates
lgalabru Feb 2, 2024
5752d4b
fix: imitate overflow behavior
lgalabru Feb 2, 2024
8ff4b1d
fix: transfer duplicates
lgalabru Feb 5, 2024
5292230
chore: display git hash
lgalabru Feb 5, 2024
db5ce4e
fix: add unicity constraints, cascade changes
lgalabru Feb 6, 2024
4dc9f76
feat: confirm before deleting blocks
lgalabru Feb 6, 2024
231a231
fix: transfer offset
lgalabru Feb 7, 2024
09df75c
feat: introduce stream-indexing flag
lgalabru Feb 7, 2024
5c181c1
fix: move on after 20 retry
lgalabru Feb 8, 2024
5d5cbfd
fix: speed up retries
lgalabru Feb 8, 2024
64d0e3e
chore: fix ordinals reinscriptions
lgalabru Feb 9, 2024
f68e8f5
fix: git commit
lgalabru Feb 9, 2024
45b5890
fix: git-commit ENV
lgalabru Feb 9, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ jobs:
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
file: ./dockerfiles/components/ordhook.dockerfile
build-args: |
GIT_COMMIT=${{ env.GITHUB_SHA_SHORT }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Only push if (there's a new release on main branch, or if building a non-main branch) and (Only run on non-PR events or only PRs that aren't from forks)
Expand Down
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions components/ordhook-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ toml = { version = "0.5.6", features = ["preserve_order"], optional = true }
ctrlc = { version = "3.2.2", optional = true }
tcmalloc2 = { version = "0.1.2+2.13", optional = true }

[target.'cfg(not(target_env = "msvc"))'.dependencies]
tcmalloc2 = "0.1.2+2.13"

[features]
default = ["cli"]
cli = ["clap", "clap_generate", "toml", "ctrlc", "hiro-system-kit/log"]
Expand Down
29 changes: 29 additions & 0 deletions components/ordhook-cli/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use std::process::Command;

fn current_git_hash() -> Option<String> {
if option_env!("GIT_COMMIT") == None {
let commit = Command::new("git")
.arg("log")
.arg("-1")
.arg("--pretty=format:%h") // Abbreviated commit hash
.current_dir(env!("CARGO_MANIFEST_DIR"))
.output();

if let Ok(commit) = commit {
if let Ok(commit) = String::from_utf8(commit.stdout) {
return Some(commit);
}
}
} else {
return option_env!("GIT_COMMIT").map(String::from);
}

None
}

fn main() {
// note: add error checking yourself.
if let Some(git) = current_git_hash() {
println!("cargo:rustc-env=GIT_COMMIT={}", git);
}
}
27 changes: 24 additions & 3 deletions components/ordhook-cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ struct StartCommand {
/// Check blocks integrity
#[clap(long = "check-blocks-integrity")]
pub block_integrity_check: bool,
/// Stream indexing to observers
#[clap(long = "stream-indexing")]
pub stream_indexing_to_observers: bool,
}

#[derive(Subcommand, PartialEq, Clone, Debug)]
Expand Down Expand Up @@ -725,8 +728,11 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
}

let ordhook_config = config.get_ordhook_config();

info!(ctx.expect_logger(), "Starting service...",);
let version = env!("GIT_COMMIT");
info!(
ctx.expect_logger(),
"Starting service (git_commit = {})...", version
);

let start_block = match cmd.start_at_block {
Some(entry) => entry,
Expand Down Expand Up @@ -758,7 +764,12 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {

let mut service = Service::new(config, ctx.clone());
return service
.run(predicates, None, cmd.block_integrity_check)
.run(
predicates,
None,
cmd.block_integrity_check,
cmd.stream_indexing_to_observers,
)
.await;
}
},
Expand Down Expand Up @@ -913,6 +924,16 @@ async fn handle_command(opts: Opts, ctx: &Context) -> Result<(), String> {
let inscriptions_db_conn_rw =
open_readwrite_ordhook_db_conn(&config.expected_cache_path(), ctx)?;

println!(
"{} blocks will be deleted. Confirm? [Y/n]",
cmd.end_block - cmd.start_block + 1
);
let mut buffer = String::new();
std::io::stdin().read_line(&mut buffer).unwrap();
if buffer.starts_with('n') {
return Err("Deletion aborted".to_string());
}

delete_data_in_ordhook_db(
cmd.start_block,
cmd.end_block,
Expand Down
4 changes: 4 additions & 0 deletions components/ordhook-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ extern crate serde_derive;
#[macro_use]
extern crate hiro_system_kit;

#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: tcmalloc2::TcMalloc = tcmalloc2::TcMalloc;

pub mod cli;
pub mod config;

Expand Down
2 changes: 1 addition & 1 deletion components/ordhook-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ serde_json = "1"
serde_derive = "1"
hex = "0.4.3"
rand = "0.8.5"
chainhook-sdk = { version = "=0.12.2", features = ["zeromq"] }
chainhook-sdk = { version = "=0.12.4", features = ["zeromq"] }
# chainhook-sdk = { version = "=0.12.1", path = "../../../chainhook/components/chainhook-sdk", features = ["zeromq"] }
hiro-system-kit = "0.3.1"
reqwest = { version = "0.11", default-features = false, features = [
Expand Down
88 changes: 56 additions & 32 deletions components/ordhook-core/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,41 +56,63 @@ pub enum SatPosition {
Fee(u64),
}

pub fn resolve_absolute_pointer(inputs: &Vec<u64>, absolute_pointer_value: u64) -> (usize, u64) {
let mut selected_index = 0;
let mut cumulated_input_value = 0;
// Check for overflow
let total: u64 = inputs.iter().sum();
if absolute_pointer_value > total {
return (0, 0);
}
// Identify the input + satoshi offset being inscribed
for (index, input_value) in inputs.iter().enumerate() {
if (cumulated_input_value + input_value) > absolute_pointer_value {
selected_index = index;
break;
}
cumulated_input_value += input_value;
}
let relative_pointer_value = absolute_pointer_value - cumulated_input_value;
(selected_index, relative_pointer_value)
}

pub fn compute_next_satpoint_data(
_tx_index: usize,
input_index: usize,
offset_intra_input: u64,
inputs: &Vec<u64>,
outputs: &Vec<u64>,
pointer_from_inscription: u64,
relative_pointer_value: u64,
_ctx: Option<&Context>,
) -> SatPosition {
let mut offset_cross_inputs = 0;
let mut absolute_offset_in_inputs = 0;
for (index, input_value) in inputs.iter().enumerate() {
if index == input_index {
break;
}
offset_cross_inputs += input_value;
absolute_offset_in_inputs += input_value;
}
offset_cross_inputs += offset_intra_input;
offset_cross_inputs += pointer_from_inscription;
absolute_offset_in_inputs += relative_pointer_value;

let mut offset_intra_outputs = 0;
let mut output_index = 0;
let mut absolute_offset_of_first_satoshi_in_selected_output = 0;
let mut selected_output_index = 0;
let mut floating_bound = 0;

for (index, output_value) in outputs.iter().enumerate() {
floating_bound += output_value;
output_index = index;
if floating_bound > offset_cross_inputs {
selected_output_index = index;
if floating_bound > absolute_offset_in_inputs {
break;
}
offset_intra_outputs += output_value;
absolute_offset_of_first_satoshi_in_selected_output += output_value;
}

if output_index == (outputs.len() - 1) && offset_cross_inputs >= floating_bound {
if selected_output_index == (outputs.len() - 1) && absolute_offset_in_inputs >= floating_bound {
// Satoshi spent in fees
return SatPosition::Fee(offset_cross_inputs - floating_bound);
return SatPosition::Fee(absolute_offset_in_inputs - floating_bound);
}
SatPosition::Output((output_index, (offset_cross_inputs - offset_intra_outputs)))
let relative_offset_in_selected_output =
absolute_offset_in_inputs - absolute_offset_of_first_satoshi_in_selected_output;
SatPosition::Output((selected_output_index, relative_offset_in_selected_output))
}

pub fn should_sync_rocks_db(config: &Config, ctx: &Context) -> Result<Option<(u64, u64)>, String> {
Expand Down Expand Up @@ -196,55 +218,57 @@ pub fn should_sync_ordhook_db(
#[test]
fn test_identify_next_output_index_destination() {
assert_eq!(
compute_next_satpoint_data(0, 10, &vec![20, 30, 45], &vec![20, 30, 45], 0),
compute_next_satpoint_data(0, 0, &vec![20, 30, 45], &vec![20, 30, 45], 10, None),
SatPosition::Output((0, 10))
);
assert_eq!(
compute_next_satpoint_data(0, 20, &vec![20, 30, 45], &vec![20, 30, 45], 0),
compute_next_satpoint_data(0, 0, &vec![20, 30, 45], &vec![20, 30, 45], 20, None),
SatPosition::Output((1, 0))
);
assert_eq!(
compute_next_satpoint_data(1, 5, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Output((1, 5))
compute_next_satpoint_data(0, 1, &vec![20, 30, 45], &vec![20, 30, 45], 25, None),
SatPosition::Output((1, 25))
);
assert_eq!(
compute_next_satpoint_data(1, 6, &vec![20, 30, 45], &vec![20, 5, 45], 0),
SatPosition::Output((2, 1))
compute_next_satpoint_data(0, 1, &vec![20, 30, 45], &vec![20, 5, 45], 26, None),
SatPosition::Output((2, 21))
);
assert_eq!(
compute_next_satpoint_data(1, 10, &vec![10, 10, 10], &vec![30], 0),
SatPosition::Output((0, 20))
compute_next_satpoint_data(0, 1, &vec![10, 10, 10], &vec![30], 20, None),
SatPosition::Fee(0)
);
assert_eq!(
compute_next_satpoint_data(0, 30, &vec![10, 10, 10], &vec![30], 0),
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30], 30, None),
SatPosition::Fee(0)
);
assert_eq!(
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30], 0),
compute_next_satpoint_data(0, 0, &vec![10, 10, 10], &vec![30], 0, None),
SatPosition::Output((0, 0))
);
assert_eq!(
compute_next_satpoint_data(2, 45, &vec![20, 30, 45], &vec![20, 30, 45], 0),
SatPosition::Fee(0)
compute_next_satpoint_data(0, 2, &vec![20, 30, 45], &vec![20, 30, 45], 95, None),
SatPosition::Fee(50)
);
assert_eq!(
compute_next_satpoint_data(
2,
0,
2,
&vec![1000, 600, 546, 63034],
&vec![1600, 10000, 15000],
0
1600,
None
),
SatPosition::Output((1, 0))
SatPosition::Output((1, 1600))
);
assert_eq!(
compute_next_satpoint_data(
3,
0,
3,
&vec![6100, 148660, 103143, 7600],
&vec![81434, 173995],
0
257903,
None
),
SatPosition::Fee(2474)
SatPosition::Fee(260377)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
augment_block_with_ordinals_inscriptions_data_and_write_to_db_tx,
parallelize_inscription_data_computations, SequenceCursor,
},
inscription_tracking::augment_block_with_ordinals_transfer_data,
satoshi_tracking::augment_block_with_ordinals_transfer_data,
},
OrdhookConfig,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ use crate::{
pipeline::{PostProcessorCommand, PostProcessorController, PostProcessorEvent},
protocol::{
inscription_sequencing::consolidate_block_with_pre_computed_ordinals_data,
inscription_tracking::augment_block_with_ordinals_transfer_data,
satoshi_tracking::augment_block_with_ordinals_transfer_data,
},
},
db::{
insert_new_inscriptions_from_block_in_locations, open_readwrite_ordhook_db_conn,
insert_entries_from_block_in_inscriptions, open_readwrite_ordhook_db_conn,
remove_entries_from_locations_at_block_height,
},
};
Expand Down Expand Up @@ -83,11 +83,7 @@ pub fn start_transfers_recomputing_processor(
&ctx,
);

insert_new_inscriptions_from_block_in_locations(
block,
&inscriptions_db_tx,
&ctx,
);
insert_entries_from_block_in_inscriptions(block, &inscriptions_db_tx, &ctx);

augment_block_with_ordinals_transfer_data(
block,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub fn parse_inscriptions_from_witness(
witness_bytes: Vec<Vec<u8>>,
txid: &str,
) -> Option<Vec<OrdinalInscriptionRevealData>> {
// Efficient debugging: Isolate one specific transaction
// if !txid.eq("aa2ab56587c7d6609c95157e6dff37c5c3fa6531702f41229a289a5613887077") {
// return None
// }

let witness = Witness::from_slice(&witness_bytes);
let tapscript = witness.tapscript()?;
let envelopes: Vec<Envelope<Inscription>> = RawEnvelope::from_tapscript(tapscript, input_index)
Expand Down Expand Up @@ -83,7 +88,7 @@ pub fn parse_inscriptions_from_witness(
inscription_input_index: input_index,
tx_index: 0,
inscription_output_value: 0,
inscription_pointer: envelope.payload.pointer().unwrap_or(0),
inscription_pointer: envelope.payload.pointer(),
inscription_fee: 0,
inscription_number: OrdinalInscriptionNumber::zero(),
inscriber_address: None,
Expand Down
Loading
Loading