diff --git a/.travis.yml b/.travis.yml index ea643450..f4405771 100755 --- a/.travis.yml +++ b/.travis.yml @@ -79,7 +79,6 @@ install: - if [[ $LINUX && $GCC && $DYNAMIC ]]; then export CC=gcc-4.8; export CXX=g++-4.8; fi # Download and install packages. - - if [[ $OSX && $CLANG && $DYNAMIC ]]; then brew install boost; fi - if [[ $OSX && $CLANG && $DYNAMIC ]]; then brew install bash-completion; fi script: diff --git a/data/bs.cfg b/data/bs.cfg index c1f6cd8c..78d3b67a 100644 --- a/data/bs.cfg +++ b/data/bs.cfg @@ -27,8 +27,10 @@ threads = 0 protocol_maximum = 70013 # The minimum network protocol version, defaults to 31402. protocol_minimum = 31402 -# The services exposed by network connections, defaults to 1 (full node). -services = 1 +# The services exposed by network connections, defaults to 9 (full node, witness). +services = 9 +# The advertised services that cause a peer to be dropped, defaults to 160. +invalid_services = 160 # The magic number for message headers, defaults to 3652501241 (use 118034699 for testnet). identifier = 3652501241 # Validate the checksum of network messages, defaults to false. @@ -158,6 +160,12 @@ bip68 = true bip112 = true # Use median time past for locktime, defaults to true (soft fork). bip113 = true +# Segregated witness consensus layer, defaults to true (soft fork). +bip141 = true +# Version 0 transaction digest, defaults to true (soft fork). +bip143 = true +# Prevent dummy value malleability, defaults to true (soft fork). +bip147 = true [node] # The time to wait for a requested block, defaults to 60. diff --git a/include/bitcoin/server/interface/blockchain.hpp b/include/bitcoin/server/interface/blockchain.hpp index 519d0d66..a678dd72 100644 --- a/include/bitcoin/server/interface/blockchain.hpp +++ b/include/bitcoin/server/interface/blockchain.hpp @@ -43,6 +43,10 @@ class BCS_API blockchain static void fetch_transaction(server_node& node, const message& request, send_handler handler); + /// Fetch a transaction with witness from the blockchain by its hash. + static void fetch_transaction2(server_node& node, + const message& request, send_handler handler); + /// Fetch the current height of the blockchain. static void fetch_last_height(server_node& node, const message& request, send_handler handler); diff --git a/include/bitcoin/server/interface/transaction_pool.hpp b/include/bitcoin/server/interface/transaction_pool.hpp index 17a4682a..74252756 100644 --- a/include/bitcoin/server/interface/transaction_pool.hpp +++ b/include/bitcoin/server/interface/transaction_pool.hpp @@ -36,6 +36,10 @@ class BCS_API transaction_pool static void fetch_transaction(server_node& node, const message& request, send_handler handler); + /// Fetch a transaction with witness from tx pool (or chain), by its hash. + static void fetch_transaction2(server_node& node, const message& request, + send_handler handler); + /// Save to tx pool and announce to all connected peers. static void broadcast(server_node& node, const message& request, send_handler handler); diff --git a/src/interface/blockchain.cpp b/src/interface/blockchain.cpp index f49b4306..589986ed 100644 --- a/src/interface/blockchain.cpp +++ b/src/interface/blockchain.cpp @@ -94,7 +94,29 @@ void blockchain::fetch_transaction(server_node& node, const message& request, const auto hash = deserial.read_hash(); // The response is restricted to confirmed transactions. - node.chain().fetch_transaction(hash, true, + // This response excludes witness data so as not to break old parsers. + node.chain().fetch_transaction(hash, true, false, + std::bind(&blockchain::transaction_fetched, + _1, _2, _3, _4, request, handler)); +} + +void blockchain::fetch_transaction2(server_node& node, const message& request, + send_handler handler) +{ + const auto& data = request.data(); + + if (data.size() != hash_size) + { + handler(message(request, error::bad_stream)); + return; + } + + auto deserial = make_safe_deserializer(data.begin(), data.end()); + const auto hash = deserial.read_hash(); + + // The response is restricted to confirmed transactions. + // This response includes witness data so may break old parsers. + node.chain().fetch_transaction(hash, true, true, std::bind(&blockchain::transaction_fetched, _1, _2, _3, _4, request, handler)); } diff --git a/src/interface/transaction_pool.cpp b/src/interface/transaction_pool.cpp index 27b983b7..15ecacef 100644 --- a/src/interface/transaction_pool.cpp +++ b/src/interface/transaction_pool.cpp @@ -48,7 +48,29 @@ void transaction_pool::fetch_transaction(server_node& node, const auto hash = deserial.read_hash(); // The response allows confirmed and unconfirmed transactions. - node.chain().fetch_transaction(hash, false, + // This response excludes witness data so as not to break old parsers. + node.chain().fetch_transaction(hash, false, false, + std::bind(&transaction_pool::transaction_fetched, + _1, _2, _3, _4, request, handler)); +} + +void transaction_pool::fetch_transaction2(server_node& node, + const message& request, send_handler handler) +{ + const auto& data = request.data(); + + if (data.size() != hash_size) + { + handler(message(request, error::bad_stream)); + return; + } + + auto deserial = make_safe_deserializer(data.begin(), data.end()); + const auto hash = deserial.read_hash(); + + // The response allows confirmed and unconfirmed transactions. + // This response includes witness data so may break old parsers. + node.chain().fetch_transaction(hash, false, true, std::bind(&transaction_pool::transaction_fetched, _1, _2, _3, _4, request, handler)); } diff --git a/src/parser.cpp b/src/parser.cpp index 05dd544c..de4d1654 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -49,6 +49,8 @@ parser::parser(const configuration& defaults) parser::parser(bc::config::settings context) : configured(context) { + using serve = message::version::service; + // Logs will slow things if not rotated. configured.network.rotation_size = 10000000; @@ -58,8 +60,8 @@ parser::parser(bc::config::settings context) // A node allows 1000 host names by default. configured.network.host_pool_capacity = 1000; - // A node exposes full node (1) network services by default. - configured.network.services = message::version::service::node_network; + // Expose full node (1) and witness (8) network services by default. + configured.network.services = serve::node_network | serve::node_witness; // TODO: set this independently on each public endpoint. configured.protocol.message_size_limit = max_block_size + 100; @@ -195,7 +197,12 @@ options_metadata parser::load_settings() ( "network.services", value(&configured.network.services), - "The services exposed by network connections, defaults to 1 (full node)." + "The services exposed by network connections, defaults to 9 (full node, witness)." + ) + ( + "network.invalid_services", + value(&configured.network.invalid_services), + "The advertised services that cause a peer to be dropped, defaults to 160." ) ( "network.validate_checksum", @@ -418,6 +425,21 @@ options_metadata parser::load_settings() value(&configured.chain.bip113), "Use median time past for locktime, defaults to true (soft fork)." ) + ( + "fork.bip141", + value(&configured.chain.bip141), + "Segregated witness consensus layer, defaults to true (soft fork)." + ) + ( + "fork.bip143", + value(&configured.chain.bip143), + "Version 0 transaction digest, defaults to true (soft fork)." + ) + ( + "fork.bip147", + value(&configured.chain.bip147), + "Prevent dummy value malleability, defaults to true (soft fork)." + ) /* [node] */ ////( diff --git a/src/workers/query_worker.cpp b/src/workers/query_worker.cpp index 38b68a09..1a671289 100644 --- a/src/workers/query_worker.cpp +++ b/src/workers/query_worker.cpp @@ -255,6 +255,7 @@ void query_worker::attach_interface() ATTACH(blockchain, fetch_block_transaction_hashes, node_); // original ATTACH(blockchain, fetch_last_height, node_); // original ATTACH(blockchain, fetch_transaction, node_); // original + ATTACH(blockchain, fetch_transaction2, node_); // new (3.4) ATTACH(blockchain, fetch_transaction_index, node_); // original ATTACH(blockchain, fetch_spend, node_); // original ATTACH(blockchain, fetch_history3, node_); // new (3.1) @@ -264,7 +265,8 @@ void query_worker::attach_interface() ATTACH(blockchain, validate, node_); // new (3.0) ////ATTACH(transaction_pool, validate, node_); // obsoleted - ATTACH(transaction_pool, fetch_transaction, node_); // enhanced + ATTACH(transaction_pool, fetch_transaction, node_); // enhanced (3.0) + ATTACH(transaction_pool, fetch_transaction2, node_); // new (3.4) ATTACH(transaction_pool, broadcast, node_); // new (3.0) ATTACH(transaction_pool, validate2, node_); // new (3.0)