Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Aug 4, 2023
2 parents 55bf041 + caf53d7 commit 06381db
Show file tree
Hide file tree
Showing 45 changed files with 3,911 additions and 572 deletions.
11 changes: 10 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,23 @@ grammar fixes.

Pull request merge requirements:
- all CI test should pass,
- at least two "accepts"/ACKs from the repository maintainers
- at least two "accepts"/ACKs from the repository maintainers (see "refactor carve out").
- no reasonable "rejects"/NACKs from anybody who reviewed the code.

Current list of the project maintainers:

- [Hashengineering](https://github.com/hashengineering)
- [Gruve-p](https://github.com/gruve-p)

#### Refactor carve output

The repository is going through heavy refactoring and "trivial" API redesign
(eg, rename `Foo::empty` to `Foo::new`) as we push towards API stabilization. As
such reviewers are either bored or overloaded with notifications, hence we have
created a carve out to the 2-ACK rule.

A PR may be considered for merge if it has a single ACK and has sat open for at
least two weeks with no comments, questions, or NACKs.

## Coding conventions

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/groestlcoin/deser_net_msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use honggfuzz::fuzz;

fn do_test(data: &[u8]) {
let _: Result<groestlcoin::network::message::RawNetworkMessage, _> =
let _: Result<groestlcoin::p2p::message::RawNetworkMessage, _> =
groestlcoin::consensus::encode::deserialize(data);
}

Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/groestlcoin/deserialize_script.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use groestlcoin::address::Address;
use groestlcoin::blockdata::script;
use groestlcoin::consensus::encode;
use groestlcoin::network::constants::Network;
use groestlcoin::Network;
use honggfuzz::fuzz;

fn do_test(data: &[u8]) {
Expand Down
12 changes: 6 additions & 6 deletions groestlcoin/examples/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::time::{SystemTime, UNIX_EPOCH};
use std::{env, process};

use groestlcoin::consensus::{encode, Decodable};
use groestlcoin::network::{address, constants, message, message_network};
use groestlcoin::p2p::{self, address, message, message_network};
use groestlcoin::secp256k1;
use groestlcoin::secp256k1::rand::Rng;

Expand All @@ -29,7 +29,7 @@ fn main() {
let version_message = build_version_message(address);

let first_message =
message::RawNetworkMessage::new(constants::Network::Groestlcoin.magic(), version_message);
message::RawNetworkMessage::new(bitcoin::Network::Groestlcoin.magic(), version_message);

if let Ok(mut stream) = TcpStream::connect(address) {
// Send the message
Expand All @@ -47,7 +47,7 @@ fn main() {
println!("Received version message: {:?}", reply.payload());

let second_message = message::RawNetworkMessage::new(
constants::Network::Groestlcoin.magic(),
groestlcoin::Network::Groestlcoin.magic(),
message::NetworkMessage::Verack,
);

Expand Down Expand Up @@ -75,16 +75,16 @@ fn build_version_message(address: SocketAddr) -> message::NetworkMessage {
let my_address = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0);

// "bitfield of features to be enabled for this connection"
let services = constants::ServiceFlags::NONE;
let services = p2p::ServiceFlags::NONE;

// "standard UNIX timestamp in seconds"
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).expect("Time error").as_secs();

// "The network address of the node receiving this message"
let addr_recv = address::Address::new(&address, constants::ServiceFlags::NONE);
let addr_recv = address::Address::new(&address, p2p::ServiceFlags::NONE);

// "The network address of the node emitting this message"
let addr_from = address::Address::new(&my_address, constants::ServiceFlags::NONE);
let addr_from = address::Address::new(&my_address, p2p::ServiceFlags::NONE);

// "Node random nonce, randomly generated every time a version packet is sent. This nonce is used to detect connections to self."
let nonce: u64 = secp256k1::rand::thread_rng().gen();
Expand Down
16 changes: 4 additions & 12 deletions groestlcoin/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ use crate::blockdata::constants::{
};
use crate::blockdata::script::witness_program::{self, WitnessProgram};
use crate::blockdata::script::witness_version::{self, WitnessVersion};
use crate::blockdata::script::{self, Script, ScriptBuf};
use crate::crypto::key::{PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey};
use crate::hash_types::{PubkeyHash, ScriptHash};
use crate::network::constants::Network;
use crate::blockdata::script::{self, Script, ScriptBuf, ScriptHash};
use crate::crypto::key::{PubkeyHash, PublicKey, TapTweak, TweakedPublicKey, UntweakedPublicKey};
use crate::network::Network;
use crate::prelude::*;
use crate::taproot::TapNodeHash;

Expand Down Expand Up @@ -718,13 +717,6 @@ impl Address {
///
pub fn is_spend_standard(&self) -> bool { self.address_type().is_some() }

/// Checks whether or not the address is following Bitcoin standardness rules.
///
/// SegWit addresses with unassigned witness versions or non-standard program sizes are
/// considered non-standard.
#[deprecated(since = "0.30.0", note = "Use Address::is_spend_standard instead")]
pub fn is_standard(&self) -> bool { self.address_type().is_some() }

/// Constructs an [`Address`] from an output script (`scriptPubkey`).
pub fn from_script(script: &Script, network: Network) -> Result<Address, Error> {
Ok(Address::new(network, Payload::from_script(script)?))
Expand Down Expand Up @@ -996,7 +988,7 @@ mod tests {

use super::*;
use crate::crypto::key::PublicKey;
use crate::network::constants::Network::{Groestlcoin, Testnet};
use crate::network::Network::{Groestlcoin, Testnet};

fn roundtrips(addr: &Address) {
assert_eq!(
Expand Down
26 changes: 0 additions & 26 deletions groestlcoin/src/base58.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ static BASE58_DIGITS: [Option<u8>; 128] = [
Some(55), Some(56), Some(57), None, None, None, None, None, // 120-127
];

/// Decodes a base58-encoded string into a byte vector.
#[deprecated(since = "0.30.0", note = "Use base58::decode() instead")]
pub fn from(data: &str) -> Result<Vec<u8>, Error> { decode(data) }

/// Decodes a base58-encoded string into a byte vector.
pub fn decode(data: &str) -> Result<Vec<u8>, Error> {
// 11/15 is just over log_256(58)
Expand Down Expand Up @@ -70,10 +66,6 @@ pub fn decode(data: &str) -> Result<Vec<u8>, Error> {
Ok(ret)
}

/// Decodes a base58check-encoded string into a byte vector verifying the checksum.
#[deprecated(since = "0.30.0", note = "Use base58::decode_check() instead")]
pub fn from_check(data: &str) -> Result<Vec<u8>, Error> { decode_check(data) }

/// Decodes a base58check-encoded string into a byte vector verifying the checksum.
pub fn decode_check(data: &str) -> Result<Vec<u8>, Error> {
let mut ret: Vec<u8> = decode(data)?;
Expand All @@ -97,19 +89,9 @@ pub fn decode_check(data: &str) -> Result<Vec<u8>, Error> {
Ok(ret)
}

/// Encodes `data` as a base58 string.
#[deprecated(since = "0.30.0", note = "Use base58::encode() instead")]
pub fn encode_slice(data: &[u8]) -> String { encode(data) }

/// Encodes `data` as a base58 string (see also `base58::encode_check()`).
pub fn encode(data: &[u8]) -> String { encode_iter(data.iter().cloned()) }

/// Encodes `data` as a base58 string including the checksum.
///
/// The checksum is the first four bytes of the groestld of the data, concatenated onto the end.
#[deprecated(since = "0.30.0", note = "Use base58::encode_check() instead")]
pub fn check_encode_slice(data: &[u8]) -> String { encode_check(data) }

/// Encodes `data` as a base58 string including the checksum.
///
/// The checksum is the first four bytes of the groestld of the data, concatenated onto the end.
Expand All @@ -118,14 +100,6 @@ pub fn encode_check(data: &[u8]) -> String {
encode_iter(data.iter().cloned().chain(checksum[0..4].iter().cloned()))
}

/// Encodes `data` as base58, including the checksum, into a formatter.
///
/// The checksum is the first four bytes of the groestld of the data, concatenated onto the end.
#[deprecated(since = "0.30.0", note = "Use base58::encode_check_to_fmt() instead")]
pub fn check_encode_slice_to_fmt(fmt: &mut fmt::Formatter, data: &[u8]) -> fmt::Result {
encode_check_to_fmt(fmt, data)
}

/// Encodes a slice as base58, including the checksum, into a formatter.
///
/// The checksum is the first four bytes of the groestld of the data, concatenated onto the end.
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/bip32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use crate::crypto::key::{self, KeyPair, PrivateKey, PublicKey};
use crate::hash_types::XpubIdentifier;
use crate::internal_macros::impl_bytes_newtype;
use crate::io::Write;
use crate::network::constants::Network;
use crate::network::Network;
use crate::prelude::*;

/// A chain code
Expand Down Expand Up @@ -866,7 +866,7 @@ mod tests {
use super::ChildNumber::{Hardened, Normal};
use super::*;
use crate::internal_macros::hex;
use crate::network::constants::Network::{self, Groestlcoin};
use crate::network::Network::{self, Groestlcoin};

#[test]
fn test_parse_derivation_path() {
Expand Down
4 changes: 2 additions & 2 deletions groestlcoin/src/blockdata/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::blockdata::script;
use crate::blockdata::transaction::{OutPoint, Sequence, Transaction, TxIn, TxOut};
use crate::blockdata::witness::Witness;
use crate::internal_macros::impl_bytes_newtype;
use crate::network::constants::Network;
use crate::network::Network;
use crate::pow::CompactTarget;
use crate::Amount;

Expand Down Expand Up @@ -198,7 +198,7 @@ mod test {
use crate::blockdata::locktime::absolute;
use crate::consensus::encode::serialize;
use crate::internal_macros::hex;
use crate::network::constants::Network;
use crate::network::Network;

#[test]
fn bitcoin_genesis_first_transaction() {
Expand Down
46 changes: 44 additions & 2 deletions groestlcoin/src/blockdata/fee_rate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,37 @@ impl FeeRate {

/// Checked weight multiplication.
///
/// Computes `self * rhs` where rhs is of type Weight. `None` is returned if an overflow
/// occured.
/// Computes `self * rhs` where rhs is of type Weight. `None` is returned if an overflow
/// occurred.
pub fn checked_mul_by_weight(self, rhs: Weight) -> Option<Amount> {
self.0.checked_mul(rhs.to_wu()).map(Amount::from_sat)
}

/// Calculates fee by multiplying this fee rate by weight, in weight units, returning `None`
/// if overflow occurred.
///
/// This is equivalent to `Self::checked_mul_by_weight()`.
///
/// # Examples
///
/// ```no_run
/// # use bitcoin::{absolute, FeeRate, Transaction};
/// # // Dummy transaction.
/// # let tx = Transaction { version: 1, lock_time: absolute::LockTime::ZERO, input: vec![], output: vec![] };
///
/// let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/vbyte is valid");
/// let fee = rate.fee_wu(tx.weight());
/// ```
pub fn fee_wu(self, weight: Weight) -> Option<Amount> { self.checked_mul_by_weight(weight) }

/// Calculates fee by multiplying this fee rate by weight, in virtual bytes, returning `None`
/// if overflow occurred.
///
/// This is equivalent to converting `vb` to `weight` using `Weight::from_vb` and then calling
/// `Self::fee_wu(weight)`.
pub fn fee_vb(self, vb: u64) -> Option<Amount> {
Weight::from_vb(vb).and_then(|w| self.fee_wu(w))
}
}

/// Alternative will display the unit.
Expand Down Expand Up @@ -199,4 +225,20 @@ mod tests {
let fee_rate = FeeRate(10).checked_div(0);
assert!(fee_rate.is_none());
}

#[test]
fn fee_convenience_functions_agree() {
use crate::blockdata::transaction::Transaction;
use crate::consensus::Decodable;
use crate::internal_macros::hex;

const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";

let raw_tx = hex!(SOME_TX);
let tx: Transaction = Decodable::consensus_decode(&mut raw_tx.as_slice()).unwrap();

let rate = FeeRate::from_sat_per_vb(1).expect("1 sat/byte is valid");

assert_eq!(rate.fee_vb(tx.vsize() as u64), rate.fee_wu(tx.weight()));
}
}
2 changes: 1 addition & 1 deletion groestlcoin/src/blockdata/script/borrowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::blockdata::opcodes::{self};
use crate::blockdata::script::witness_version::WitnessVersion;
use crate::blockdata::script::{
bytes_to_asm_fmt, Builder, Instruction, InstructionIndices, Instructions, ScriptBuf,
ScriptHash, WScriptHash,
};
use crate::consensus::Encodable;
use crate::hash_types::{ScriptHash, WScriptHash};
use crate::key::{PublicKey, UntweakedPublicKey};
use crate::policy::DUST_RELAY_TX_FEE;
use crate::prelude::*;
Expand Down
Loading

0 comments on commit 06381db

Please sign in to comment.