Skip to content

Commit

Permalink
Merge pull request #782 from evoskuil/version3
Browse files Browse the repository at this point in the history
version 3.2.0
  • Loading branch information
evoskuil authored May 2, 2017
2 parents 546ad08 + 6b4a0b2 commit 0754766
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 125 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
AC_PREREQ([2.65])

# Process command-line arguments and perform initialization and verification.
AC_INIT([libbitcoin], [3.1.0], [[email protected]])
AC_INIT([libbitcoin], [3.2.0], [[email protected]])

# Do compilation tests.
AC_LANG(C++)
Expand Down
6 changes: 4 additions & 2 deletions include/bitcoin/bitcoin/chain/chain_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,10 @@ class BC_API chain_state
static map get_map(size_t height, const checkpoints& checkpoints,
uint32_t forks);

static uint32_t signal_version(uint32_t forks);

/// Create pool state from top block chain state.
chain_state(const chain_state& top, uint32_t version);
chain_state(const chain_state& top);

/// Create block state from pool chain state of same height.
chain_state(const chain_state& pool, const chain::block& block);
Expand Down Expand Up @@ -173,7 +175,7 @@ class BC_API chain_state
static size_t collision_height(size_t height, uint32_t forks,
const checkpoints& checkpoints);

static data to_pool(const chain_state& top, uint32_t version);
static data to_pool(const chain_state& top);
static data to_block(const chain_state& pool_state, const block& block);

static uint32_t work_required_retarget(const data& values);
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/bitcoin/chain/output.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class BC_API output

/// The payment address extracted from this output as a standard script.
wallet::payment_address address() const;
bool is_dust(uint64_t minimum_output_value) const;

// Validation.
//-----------------------------------------------------------------------------
Expand Down
14 changes: 7 additions & 7 deletions include/bitcoin/bitcoin/chain/script.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,25 @@ class BC_API script
return (fork & active_forks) != 0;
}

/// No-code patterns (consensus).
/// Consensus patterns.
static bool is_push_only(const operation::list& ops);
static bool is_relaxed_push(const operation::list& ops);
static bool is_coinbase_pattern(const operation::list& ops, size_t height);

/// Null-data pattern (standard).
/// Common output patterns (psh is also consensus).
static bool is_null_data_pattern(const operation::list& ops);

/// Payment script patterns (standard, psh is also consensus).
static bool is_pay_multisig_pattern(const operation::list& ops);
static bool is_pay_public_key_pattern(const operation::list& ops);
static bool is_pay_key_hash_pattern(const operation::list& ops);
static bool is_pay_script_hash_pattern(const operation::list& ops);

/// Signature script patterns (standard).
/// Common input patterns.
static bool is_sign_multisig_pattern(const operation::list& ops);
static bool is_sign_public_key_pattern(const operation::list& ops);
static bool is_sign_key_hash_pattern(const operation::list& ops);
static bool is_sign_script_hash_pattern(const operation::list& ops);

/// Stack factories (standard).
/// Stack factories.
static operation::list to_null_data_pattern(data_slice data);
static operation::list to_pay_public_key_pattern(data_slice point);
static operation::list to_pay_key_hash_pattern(const short_hash& hash);
Expand All @@ -177,11 +175,13 @@ class BC_API script
// Utilities (non-static).
//-------------------------------------------------------------------------

// Common pattern detection.
machine::script_pattern pattern() const;

// Consensus computations.
size_t sigops(bool embedded) const;
size_t embedded_sigops(const script& prevout_script) const;
void find_and_delete(const data_stack& endorsements);
////bool is_coinbase_pattern(size_t height) const;
bool is_unspendable() const;

// Validation.
Expand Down
2 changes: 2 additions & 0 deletions include/bitcoin/bitcoin/chain/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ class BC_API transaction
bool is_overspent() const;
bool is_internal_double_spend() const;
bool is_double_spend(bool include_unconfirmed) const;
bool is_dusty(uint64_t minimum_output_value) const;
bool is_missing_previous_outputs() const;
bool is_final(size_t block_height) const;
bool is_final(size_t block_height, uint32_t block_time) const;
bool is_locktime_conflict() const;

Expand Down
10 changes: 6 additions & 4 deletions include/bitcoin/bitcoin/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,22 @@ enum error_code_t
channel_timeout = 13,
address_blocked = 44,
channel_stopped = 45,
peer_throttling = 73,

// database
store_block_duplicate = 66,
store_block_invalid_height = 67,
store_block_missing_parent = 68,

// block pool
// blockchain
duplicate_block = 51,
orphan_block = 5,
invalid_previous_block = 24,
insufficient_work = 48,

// transaction pool
orphan_transaction = 14,
insufficient_fee = 70,
dusty_transaction = 76,
stale_chain = 75,

// check header
invalid_proof_of_work = 26,
Expand All @@ -105,7 +106,7 @@ enum error_code_t
block_legacy_sigop_limit = 30,

// accept block
non_final_transaction = 34,
block_non_final = 34,
coinbase_height_mismatch = 37,
coinbase_value_limit = 41,
block_embedded_sigop_limit = 52,
Expand All @@ -121,6 +122,7 @@ enum error_code_t
transaction_legacy_sigop_limit = 54,

// accept transaction
transaction_non_final = 74,
premature_validation = 69,
unspent_duplicate = 38,
missing_previous_output = 19,
Expand Down
38 changes: 29 additions & 9 deletions include/bitcoin/bitcoin/impl/machine/operation.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ inline const data_chunk& operation::data() const
}

// Utilities.
//-------------------------------------------------------------------------
//-----------------------------------------------------------------------------

// private
//*************************************************************************
//*****************************************************************************
// CONSENSUS: op data size is limited to 520 bytes, which requires no more
// than two bytes to encode. However the four byte encoding can represent
// a value of any size, so remains valid despite the data size limit.
//*************************************************************************
//*****************************************************************************
inline uint32_t operation::read_data_size(opcode code, reader& source)
{
BC_CONSTEXPR auto op_75 = static_cast<uint8_t>(opcode::push_size_75);
Expand Down Expand Up @@ -235,7 +235,7 @@ inline uint8_t operation::opcode_to_positive(opcode code)
{
BITCOIN_ASSERT(is_positive(code));
BC_CONSTEXPR auto op_81 = static_cast<uint8_t>(opcode::push_positive_1);
return static_cast<uint8_t>(code)-op_81 + 1;
return static_cast<uint8_t>(code) - op_81 + 1;
}

// [0..79, 81..96]
Expand Down Expand Up @@ -270,9 +270,27 @@ inline bool operation::is_positive(opcode code)
return value >= op_81 && value <= op_96;
}

inline bool operation::is_reserved(opcode code)
{
BC_CONSTEXPR auto op_186 = static_cast<uint8_t>(opcode::reserved_186);
BC_CONSTEXPR auto op_255 = static_cast<uint8_t>(opcode::reserved_255);

switch (code)
{
case opcode::reserved_80:
case opcode::reserved_98:
case opcode::reserved_137:
case opcode::reserved_138:
return true;
default:
const auto value = static_cast<uint8_t>(code);
return value >= op_186 && value <= op_255;
}
}

//*****************************************************************************
// CONSENSUS: the codes VERIF and VERNOTIF are in the conditional range yet are
// not handled. As a result satoshi always processes them in the op swtich.
// not handled. As a result satoshi always processes them in the op switch.
// This causes them to always fail as unhandled. It is misleading that the
// satoshi test cases refer to these as reserved codes. These two codes behave
// exactly as the explicitly disabled codes. On the other hand VER is not within
Expand Down Expand Up @@ -325,7 +343,7 @@ inline bool operation::is_conditional(opcode code)
}

//*****************************************************************************
// CONSENSUS: this test includes the satoshi 'reserved' code.
// CONSENSUS: this test explicitly includes the satoshi 'reserved' code.
// This affects the operation count in p2sh script evaluation.
// Presumably this was an unintended consequence of range testing enums.
//*****************************************************************************
Expand All @@ -336,9 +354,6 @@ inline bool operation::is_relaxed_push(opcode code)
return value <= op_96;
}

// Validation.
//-------------------------------------------------------------------------

inline bool operation::is_push() const
{
return is_push(code_);
Expand Down Expand Up @@ -375,6 +390,11 @@ inline bool operation::is_oversized() const
return data_.size() > max_push_data_size;
}

inline bool operation::is_minimal_push() const
{
return code_ == minimal_opcode_from_data(data_);
}

} // namespace machine
} // namespace libbitcoin

Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/bitcoin/log/severity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace log {

enum class severity
{
verbose,
debug,
info,
warning,
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/bitcoin/log/sink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ typedef boost::shared_ptr<bc::ofstream> file;

/// Initializes default non-rotable libbitcoin logging sinks and formats.
void initialize(log::file& debug_file, log::file& error_file,
log::stream& output_stream, log::stream& error_stream);
log::stream& output_stream, log::stream& error_stream, bool verbose);

/// Initializes default rotable libbitcoin logging sinks and formats.
void initialize(const rotable_file& debug_file, const rotable_file& error_file,
log::stream& output_stream, log::stream& error_stream);
log::stream& output_stream, log::stream& error_stream, bool verbose);

/// Log stream operator.
formatter& operator<<(formatter& stream, severity value);
Expand Down
1 change: 1 addition & 0 deletions include/bitcoin/bitcoin/log/source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(source, severity_source)
#define BC_LOG_SEVERITY(id, level) \
BOOST_LOG_CHANNEL_SEV(bc::log::source::get(), id, bc::log::severity::level)

#define LOG_VERBOSE(module) BC_LOG_SEVERITY(module, verbose)
#define LOG_DEBUG(module) BC_LOG_SEVERITY(module, debug)
#define LOG_INFO(module) BC_LOG_SEVERITY(module, info)
#define LOG_WARNING(module) BC_LOG_SEVERITY(module, warning)
Expand Down
9 changes: 3 additions & 6 deletions include/bitcoin/bitcoin/machine/operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,23 +117,20 @@ class BC_API operation
static bool is_counted(opcode code);
static bool is_numeric(opcode code);
static bool is_positive(opcode code);
static bool is_reserved(opcode code);
static bool is_disabled(opcode code);
static bool is_conditional(opcode code);
static bool is_relaxed_push(opcode code);

// Validation.
//-------------------------------------------------------------------------

/// Categories of opcodes.
/// Categories of operations.
bool is_push() const;
bool is_counted() const;
bool is_positive() const;
bool is_disabled() const;
bool is_conditional() const;
bool is_relaxed_push() const;

/// Validate the data against the code.
bool is_oversized() const;
bool is_minimal_push() const;

protected:
operation(opcode code, data_chunk&& data, bool valid);
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/bitcoin/machine/script_pattern.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ enum class script_pattern
/// Sign Script Hash [P2SH/BIP16]
sign_script_hash,

/// The script is valid but does not conform to the standard templates.
/// The script may be valid but does not conform to the common templates.
/// Such scripts are always accepted if they are mined into blocks, but
/// transactions with non-standard scripts may not be forwarded by peers.
/// transactions with uncommon scripts may not be forwarded by peers.
non_standard
};

Expand Down
6 changes: 2 additions & 4 deletions include/bitcoin/bitcoin/math/limits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ Integer safe_subtract(Integer left, Integer right)
}

template <typename Integer>
Integer& safe_increment(Integer& value)
void safe_increment(Integer& value)
{
static BC_CONSTEXPR auto one = Integer{1};
value = safe_add(value, one);
return value;
}

template <typename Integer>
Integer& safe_decrement(Integer& value)
void safe_decrement(Integer& value)
{
static BC_CONSTEXPR auto one = Integer{1};
value = safe_subtract(value, one);
return value;
}

template <typename To, typename From, typename = SIGNED_SIGNED(To, From)>
Expand Down
2 changes: 1 addition & 1 deletion include/bitcoin/bitcoin/utility/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ inline std::string local_time()
// boost::timer::auto_cpu_timer requires the boost timer lib dependency.

/// Class to measure the execution time of a callable.
template <typename Time = asio::milliseconds, class Clock=asio::steady_clock>
template <typename Time=asio::milliseconds, class Clock=asio::steady_clock>
struct timer
{
/// Returns the quantity (count) of the elapsed time as TimeT units.
Expand Down
4 changes: 2 additions & 2 deletions include/bitcoin/bitcoin/version.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
* For interpretation of the versioning scheme see: http://semver.org
*/

#define LIBBITCOIN_VERSION "3.1.0"
#define LIBBITCOIN_VERSION "3.2.0"
#define LIBBITCOIN_MAJOR_VERSION 3
#define LIBBITCOIN_MINOR_VERSION 1
#define LIBBITCOIN_MINOR_VERSION 2
#define LIBBITCOIN_PATCH_VERSION 0

#endif
13 changes: 4 additions & 9 deletions src/chain/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,9 @@ code block::check() const
else if (is_extra_coinbases())
return error::extra_coinbases;

// This is a subset of is_internal_double_spend if one assumes that tx
// hash collisions cannot happen. But this is not the case, so we keep it.
else if (!is_distinct_transaction_set())
return error::internal_duplicate;
// This is subset of is_internal_double_spend if collisions cannot happen.
////else if (!is_distinct_transaction_set())
//// return error::internal_duplicate;

else if (is_internal_double_spend())
return error::block_internal_double_spend;
Expand All @@ -738,7 +737,6 @@ code block::check() const
// This will not make a difference unless prevouts are populated, in which
// case they are ignored. This means that p2sh sigops are not counted here.
// This is a preliminary check, the final count must come from connect().
// Reenable once sigop caching is implemented, otherwise is deoptimization.
////else if (signature_operations(false) > max_block_sigops)
//// return error::block_legacy_sigop_limit;

Expand Down Expand Up @@ -768,11 +766,9 @@ code block::accept(const chain_state& state, bool transactions) const
return error::success;

// TODO: relates timestamp to tx.locktime (pool cache min tx.timestamp).
// This recurses txs but is not applied via mempool (timestamp required).
else if (!is_final(state.height()))
return error::non_final_transaction;
return error::block_non_final;

// The coinbase tx is never seen/cached by the tx pool.
else if (bip34 && !is_valid_coinbase_script(state.height()))
return error::coinbase_height_mismatch;

Expand All @@ -781,7 +777,6 @@ code block::accept(const chain_state& state, bool transactions) const
return error::coinbase_value_limit;

// TODO: relates block limit to total of tx.sigops (pool cache tx.sigops).
// This recomputes sigops to include p2sh from prevouts.
else if (transactions && (signature_operations(bip16) > max_block_sigops))
return error::block_embedded_sigop_limit;

Expand Down
Loading

0 comments on commit 0754766

Please sign in to comment.