I'm writing functional tests that ensure that my code sending transactions using sendtoaddress is sent with the right transaction fee. These tests are failing, even though the calculation checks out.
Then I had a look at the functional tests and found this: https://github.com/bitcoin/bitcoin/blob/362f9c60a54e673bb3daa8996f86d4bc7547eb13/test/functional/test_framework/util.py#L40
The node's fee calculation can be off by 2 bytes? What is the reason for this and can it be fixed?
To reproduce
Rpc settxfee: 0.00100 (100 sat/b)
Send transaction (sendtoaddress) (2segwit inputs, 1 wrapped segwit output - Not an important detail)
The transaction reports this:
Fee: 0.00020680
vSize: 201
calculate sat/b from this and you get ~102
Expected behavior
The fee/b as set in settxfee should be used exactly (100)
Actual behavior
Effective sat/b fee of ~ 102
System information
Bitcoin core 0.18.1