From c64266a91e62bb23d1b309beec7c1861c0536430 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 24 Nov 2017 02:07:16 -0800 Subject: [PATCH 1/5] Parse segwit configuration settings. --- data/bs.cfg | 6 ++++++ src/parser.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/data/bs.cfg b/data/bs.cfg index c1f6cd8c..f1c8f4a0 100644 --- a/data/bs.cfg +++ b/data/bs.cfg @@ -158,6 +158,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/src/parser.cpp b/src/parser.cpp index 05dd544c..08331453 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -418,6 +418,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] */ ////( From ff11fa1aaf8bc3330449f856b5b7c4afcd1cef3b Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 1 Dec 2017 17:00:07 -0800 Subject: [PATCH 2/5] Add fetch_transaction2 calls (witness). --- .../bitcoin/server/interface/blockchain.hpp | 4 ++++ .../server/interface/transaction_pool.hpp | 4 ++++ src/interface/blockchain.cpp | 24 ++++++++++++++++++- src/interface/transaction_pool.cpp | 24 ++++++++++++++++++- src/workers/query_worker.cpp | 4 +++- 5 files changed, 57 insertions(+), 3 deletions(-) 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/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) From 43e25570fc90bbdc93df0a7aabc00c1d030e53f5 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Sat, 2 Dec 2017 10:26:19 -0800 Subject: [PATCH 3/5] Change default network.service to 9 (full node | witness). --- data/bs.cfg | 4 ++-- src/parser.cpp | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/data/bs.cfg b/data/bs.cfg index f1c8f4a0..fa10fbcf 100644 --- a/data/bs.cfg +++ b/data/bs.cfg @@ -27,8 +27,8 @@ 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 magic number for message headers, defaults to 3652501241 (use 118034699 for testnet). identifier = 3652501241 # Validate the checksum of network messages, defaults to false. diff --git a/src/parser.cpp b/src/parser.cpp index 08331453..05480622 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,7 @@ 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.validate_checksum", From 9ceb511918a153f998d7591546df11816642956d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Wed, 13 Dec 2017 12:19:49 -0800 Subject: [PATCH 4/5] Add invalid_services setting. --- data/bs.cfg | 2 ++ src/parser.cpp | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/data/bs.cfg b/data/bs.cfg index fa10fbcf..78d3b67a 100644 --- a/data/bs.cfg +++ b/data/bs.cfg @@ -29,6 +29,8 @@ protocol_maximum = 70013 protocol_minimum = 31402 # 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. diff --git a/src/parser.cpp b/src/parser.cpp index 05480622..de4d1654 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -199,6 +199,11 @@ options_metadata parser::load_settings() value(&configured.network.services), "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", value(&configured.network.validate_checksum), From 8492abe817a7df154dc5f9673c30b0b496ad5d88 Mon Sep 17 00:00:00 2001 From: Phillip Mienk Date: Tue, 19 Dec 2017 22:37:32 -0800 Subject: [PATCH 5/5] Bypass brew install of boost library. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) 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: