Fix null pointer in IsTrusted()
Make GetAvailableCredit run GetHash() only once per transaction.

This makes the first getbalance/getinfo 63x faster on my wallet.
Add AssertLockHeld for cs_main to ChainActive-using functions

All functions that use ChainActive but do not aquire the cs_main
lock themselves, need to be called with the cs_main lock held.

This commit adds assertions to all externally callable functions
that use chainActive or chainMostWork.

This will flag usages when built with -DDEBUG_LOCKORDER.

Conflicts:
	src/main.cpp
Solve chainActive-related locking issues

- In wallet and GUI code LOCK cs_main as well as cs_wallet when
  necessary
- In main.cpp SendMessages move the TRY_LOCK(cs_main) up, to encompass the call
  to IsInitialBlockDownload.
- Make ActivateBestChain, AddToBlockIndex, IsInitialBlockDownload,
  InitBlockIndex acquire the cs_main lock

Fixes #3997

Conflicts:
	src/qt/transactiondesc.cpp
	src/qt/transactiontablemodel.cpp
	src/qt/walletmodel.cpp
Add missing LOCK(cs_main)
estimatefee / estimatepriority RPC methods

New RPC methods: return an estimate of the fee (or priority) a
transaction needs to be likely to confirm in a given number of
blocks.

Mike Hearn created the first version of this method for estimating fees.
It works as follows:

For transactions that took 1 to N (I picked N=25) blocks to confirm,
keep N buckets with at most 100 entries in each recording the
fees-per-kilobyte paid by those transactions.

(separate buckets are kept for transactions that confirmed because
they are high-priority)

The buckets are filled as blocks are found, and are saved/restored
in a new fee_estiamtes.dat file in the data directory.

A few variations on Mike's initial scheme:

To estimate the fee needed for a transaction to confirm in X buckets,
all of the samples in all of the buckets are used and a median of
all of the data is used to make the estimate. For example, imagine
25 buckets each containing the full 100 entries. Those 2,500 samples
are sorted, and the estimate of the fee needed to confirm in the very
next block is the 50'th-highest-fee-entry in that sorted list; the
estimate of the fee needed to confirm in the next two blocks is the
150'th-highest-fee-entry, etc.

That algorithm has the nice property that estimates of how much fee
you need to pay to get confirmed in block N will always be greater
than or equal to the estimate for block N+1. It would clearly be wrong
to say "pay 11 uBTC and you'll get confirmed in 3 blocks, but pay
12 uBTC and it will take LONGER".

A single block will not contribute more than 10 entries to any one
bucket, so a single miner and a large block cannot overwhelm
the estimates.

Conflicts:
	doc/release-notes.md
	src/init.cpp
	src/main.h
	src/rpcclient.cpp
	src/rpcmining.cpp
Get rid of the static chainMostWork (optimization)
Allow ActivateBestChain to release its lock on cs_main

Conflicts:
	src/main.cpp
Move all post-chaintip-change notifications to ActivateBestChain

Conflicts:
	src/main.cpp
JSON-RPC method: prioritisetransaction <txid> <priority delta> <priority tx fee>

Accepts the transaction into mined blocks at a higher (or lower) priority

Conflicts:
	src/miner.cpp
	src/rpcclient.cpp
	src/rpcserver.cpp
Track peers' available blocks
Add a skiplist to the CBlockIndex structure.

This allows fast (O(log n)) access to far predecessor blocks.
Use it to speed up CChain::FindFork and CChain::GetLocator.

Conflicts:
	src/main.cpp
Add skiplist unit tests
Watchonly balances are shown separately in gui.

Conflicts:
	src/qt/forms/overviewpage.ui
	src/qt/overviewpage.cpp
	src/qt/overviewpage.h
	src/qt/sendcoinsdialog.cpp
	src/qt/sendcoinsdialog.h
	src/qt/transactiondesc.cpp
	src/qt/walletmodel.cpp
	src/qt/walletmodel.h
Watchonly transactions are marked in transaction history
Added argument to getbalance to include watchonly addresses and fixed errors in balance calculation.

Conflicts:
	src/wallet.h
Added argument to listaccounts to include watchonly addresses
Showing 'involvesWatchonly' property for transactions returned by 'listtransactions' and 'listsinceblock'.
It is only appended when the transaction involves a watchonly address.
Added argument to listtransactions and listsinceblock to include watchonly addresses
fixed tiny glitch and improved readability like laanwj suggested

Conflicts:
	src/wallet.cpp