Skip to content

Commit

Permalink
Consider >1 input when calculating signed tx size
Browse files Browse the repository at this point in the history
Fixes #91
  • Loading branch information
nkostoulas committed Jun 28, 2019
1 parent 7c857b0 commit 36274c9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Mainstay is accompanied by a Confirmation tool that can be run in parallel with


- Unit Testing
- `/$GOPATH/src/mainstay/run-tests.sh`
- `/$GOPATH/src/mainstay/scripts/run-tests.sh`

## Tools

Expand Down
9 changes: 6 additions & 3 deletions attestation/attestclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ func (w *AttestClient) createAttestation(paytoaddr btcutil.Address, unspent []bt
msgTx.TxIn[0].Sequence = uint32(math.Pow(2, float64(32))) - 3

// return error if txout value is less than maxFee target
maxFee := calcSignedTxFee(w.Fees.maxFee, msgTx.SerializeSize(), len(w.script0)/2, w.numOfSigs)
maxFee := calcSignedTxFee(w.Fees.maxFee, msgTx.SerializeSize(),
len(inputs)*len(w.script0)/2, len(inputs)*w.numOfSigs)
if msgTx.TxOut[0].Value < maxFee {
return nil, errors.New(ErrorInsufficientFunds)
}
Expand All @@ -378,7 +379,8 @@ func (w *AttestClient) createAttestation(paytoaddr btcutil.Address, unspent []bt

// add fees using best fee-per-byte estimate
feePerByte := w.Fees.GetFee()
fee := calcSignedTxFee(feePerByte, msgTx.SerializeSize(), len(w.script0)/2, w.numOfSigs)
fee := calcSignedTxFee(feePerByte, msgTx.SerializeSize(),
len(inputs)*len(w.script0)/2, len(inputs)*w.numOfSigs)
msgTx.TxOut[0].Value -= fee

return msgTx, nil
Expand All @@ -400,7 +402,8 @@ func (w *AttestClient) bumpAttestationFees(msgTx *wire.MsgTx) error {
feePerByteIncrement := w.Fees.GetFee() - prevFeePerByte

// increase tx fees by fee difference
feeIncrement := calcSignedTxFee(feePerByteIncrement, msgTx.SerializeSize(), len(w.script0)/2, w.numOfSigs)
feeIncrement := calcSignedTxFee(feePerByteIncrement, msgTx.SerializeSize(),
len(msgTx.TxIn)*len(w.script0)/2, len(msgTx.TxIn)*w.numOfSigs)
msgTx.TxOut[0].Value -= feeIncrement

return nil
Expand Down
6 changes: 4 additions & 2 deletions attestation/attestclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,10 @@ func TestAttestClient_FeeBumping(t *testing.T) {

newFee := client.Fees.GetFee()
newValue := tx2.TxOut[0].Value
newTxFee := calcSignedTxFee(newFee, tx2.SerializeSize(), len(client.script0)/2, client.numOfSigs)
currentTxFee := calcSignedTxFee(currentFee, tx.SerializeSize(), len(client.script0)/2, client.numOfSigs)
newTxFee := calcSignedTxFee(newFee, tx2.SerializeSize(),
len(tx2.TxIn)*len(client.script0)/2, len(tx2.TxIn)*client.numOfSigs)
currentTxFee := calcSignedTxFee(currentFee, tx.SerializeSize(),
len(tx.TxIn)*len(client.script0)/2, len(tx.TxIn)*client.numOfSigs)
assert.Equal(t, newTxFee-currentTxFee, currentValue+topupValue-newValue)
assert.Equal(t, client.Fees.minFee+client.Fees.feeIncrement, newFee)

Expand Down

0 comments on commit 36274c9

Please sign in to comment.