Exercise: Create a Valid Transaction via Your Testnet Node
Now that we understand the major elements of consensus, let's learn where to dig up data on these factors and have a look at them.
Here we'll have a closer look at some of the elements of consensus. As we've learned in this unit there are many factors in arriving at consensus. Let's have a look at how we can view info on three of those elements, the longest chain, the version of the software that we are running, and block headers that can be used to signal consensus changes.
A simple bitcoin-cli command will show us what our node thinks is the tip of the chain. Make sure your bitcoind regtest node is up and running and then try the below command.
$ bitcoin-cli getblockcount
As we are running our nodes on regtest here, the blockheight returned by this command is likely to be fairly low, maybe a few hundred.
To actively participate in Bitcoin consensus you can essentially vote on what changes you want to see on the network by deciding which version of the software to run. Let's have a look at which version of bitcoind we are running with the below bitcoind command
$ bitcoind -version
Signaling a change
A common way for miners to participate in a consensus change is to signal that they support a change via the block headers of the blocks that they mine. Both BIP-34 & BIP-9 use the block version in the block header to signal that change. As discussed in Chapter 10 of Mastering Bitcoin 2nd Edition, BIP-34 reads the version as an integer value, while BIP-9 reads it as a bitfield instead of an integer.
Since we won't find data that is relevant to the Bitcoin mainnet on our regtest node, let's have a look at block headers both on our node and using a block explorer.
To find block versions on our regtest node we'll want to first find the has of the latest block.
$ bitcoin-cli getblockchaininfo
In the output from that command find "bestblockhash" and copy it using it for the below command.
$ bitcoin-cli getblockheader [block hash]
Now, let's see what miners are currently using as block versions. Use this or a similar blockchain explorer, https://live.blockcypher.com/btc/. Via the blockcypher explorer, click on the height of the most recent block, you'll be able to find the block version by looking at the advanced details.
You can find more details on the structure of block headers here: https://developer.bitcoin.org/reference/block_chain.html
Source: Saylor Academy
This work is licensed under a Creative Commons Attribution 4.0 License.