This is a backport of core#17984
Backport note:
- Most of the PR is not relevant for us (segwit stuff or codestyle), so this includes only the commit that adds a useful new test for forcerelay permission.
- The code to build the transaction is different because Core uses some kind of dark magic to make a transaction that does not require a signature. I used a normal address and signed it, instead.