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

Update bitcoin dependencies #2281

Merged
merged 14 commits into from
Jul 21, 2023
Merged
1,186 changes: 394 additions & 792 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ axum-server = "0.5.0"
base64 = "0.21.0"
bech32 = "0.9.1"
bip39 = "2.0.0"
bitcoin = { version = "0.29.1", features = ["rand"] }
bitcoin = { version = "0.30.0", features = ["rand"] }
boilerplate = { version = "0.2.3", features = ["axum"] }
chrono = "0.4.19"
clap = { version = "3.2.18", features = ["derive", "deprecated"] }
Expand All @@ -38,9 +38,9 @@ lazy_static = "1.4.0"
log = "0.4.14"
mime = "0.3.16"
mime_guess = "2.0.4"
miniscript = "9.0.1"
miniscript = "10.0.0"
mp4 = "0.13.0"
ord-bitcoincore-rpc = "0.16.5"
ord-bitcoincore-rpc = "0.17.0"
redb = "1.0.2"
regex = "1.6.0"
rss = "2.0.1"
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ debug = 1

[dependencies]
arbitrary = { version = "1", features = ["derive"] }
bitcoin = { version = "0.29.1", features = ["rand"] }
bitcoin = { version = "0.30.0", features = ["rand"] }
libfuzzer-sys = "0.4"
ord = { path = ".." }

Expand Down
9 changes: 1 addition & 8 deletions src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl Chain {
pub(crate) fn address_from_script(
self,
script: &Script,
) -> Result<Address, bitcoin::util::address::Error> {
) -> Result<Address, bitcoin::address::Error> {
Address::from_script(script, self.network())
}

Expand All @@ -66,13 +66,6 @@ impl Chain {
Self::Regtest => data_dir.join("regtest"),
}
}

pub(crate) fn check_address_is_valid_for_network(self, address: &Address) -> Result {
if !address.is_valid_for_network(self.network()) {
bail!("Address `{address}` is not valid for {self}");
}
Ok(())
}
}

impl Display for Chain {
Expand Down
46 changes: 23 additions & 23 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use {
},
super::*,
crate::wallet::Wallet,
bitcoin::BlockHeader,
bitcoin::block::Header,
bitcoincore_rpc::{json::GetBlockHeaderResult, Client},
chrono::SubsecRound,
indicatif::{ProgressBar, ProgressStyle},
Expand Down Expand Up @@ -556,7 +556,7 @@ impl Index {
}
}

pub(crate) fn block_header(&self, hash: BlockHash) -> Result<Option<BlockHeader>> {
pub(crate) fn block_header(&self, hash: BlockHash) -> Result<Option<Header>> {
self.client.get_block_header(&hash).into_option()
}

Expand Down Expand Up @@ -2572,30 +2572,30 @@ mod tests {
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"foo")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"bar")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"qix")
.push_opcode(opcodes::all::OP_ENDIF)
.into_script();

let witness = Witness::from_vec(vec![script.into_bytes(), Vec::new()]);
let witness = Witness::from_slice(&[script.into_bytes(), Vec::new()]);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0)],
Expand Down Expand Up @@ -2679,30 +2679,30 @@ mod tests {
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"foo")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"bar")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"qix")
.push_opcode(opcodes::all::OP_ENDIF)
.into_script();

let witness = Witness::from_vec(vec![script.into_bytes(), Vec::new()]);
let witness = Witness::from_slice(&[script.into_bytes(), Vec::new()]);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0), (2, 0, 0), (3, 0, 0)],
Expand Down Expand Up @@ -2784,30 +2784,30 @@ mod tests {
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"foo")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"bar")
.push_opcode(opcodes::all::OP_ENDIF)
.push_opcode(opcodes::OP_FALSE)
.push_opcode(opcodes::all::OP_IF)
.push_slice(b"ord")
.push_slice(&[1])
.push_slice([1])
.push_slice(b"text/plain;charset=utf-8")
.push_slice(&[])
.push_slice([])
.push_slice(b"qix")
.push_opcode(opcodes::all::OP_ENDIF)
.into_script();

let witness = Witness::from_vec(vec![script.into_bytes(), Vec::new()]);
let witness = Witness::from_slice(&[script.into_bytes(), Vec::new()]);

let txid = context.rpc_server.broadcast_tx(TransactionTemplate {
inputs: &[(1, 0, 0)],
Expand Down
8 changes: 4 additions & 4 deletions src/index/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ impl Entry for BlockHash {
type Value = BlockHashValue;

fn load(value: Self::Value) -> Self {
BlockHash::from_inner(value)
BlockHash::from_raw_hash(Hash::from_byte_array(value))
}

fn store(self) -> Self::Value {
self.into_inner()
*self.as_ref()
}
}

Expand Down Expand Up @@ -72,15 +72,15 @@ impl Entry for InscriptionId {
fn load(value: Self::Value) -> Self {
let (txid, index) = value.split_at(32);
Self {
txid: Txid::from_inner(txid.try_into().unwrap()),
txid: Txid::from_raw_hash(Hash::from_slice(txid).unwrap()),
index: u32::from_be_bytes(index.try_into().unwrap()),
}
}

fn store(self) -> Self::Value {
let mut value = [0; 36];
let (txid, index) = value.split_at_mut(32);
txid.copy_from_slice(self.txid.as_inner());
txid.copy_from_slice(self.txid.as_ref());
index.copy_from_slice(&self.index.to_be_bytes());
value
}
Expand Down
11 changes: 3 additions & 8 deletions src/index/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use {
mod inscription_updater;

struct BlockData {
header: BlockHeader,
header: Header,
txdata: Vec<(Transaction, Txid)>,
}

Expand Down Expand Up @@ -102,12 +102,7 @@ impl Updater {

let mut uncommitted = 0;
let mut value_cache = HashMap::new();
loop {
let block = match rx.recv() {
Ok(block) => block,
Err(mpsc::RecvError) => break,
};

while let Ok(block) = rx.recv() {
self.index_block(
index,
&mut outpoint_sender,
Expand Down Expand Up @@ -397,7 +392,7 @@ impl Updater {
if let Some(prev_height) = self.height.checked_sub(1) {
let prev_hash = height_to_block_hash.get(&prev_height)?.unwrap();

if prev_hash.value() != block.header.prev_blockhash.as_ref() {
if prev_hash.value() != &block.header.prev_blockhash.as_raw_hash().to_byte_array() {
index.reorged.store(true, atomic::Ordering::Relaxed);
return Err(anyhow!("reorg detected at or before {prev_height}"));
}
Expand Down
Loading