Skip to content

Commit

Permalink
Merge pull request #127 from commerceblock/develop
Browse files Browse the repository at this point in the history
Release 1.2.1 - Fee bump bug
  • Loading branch information
Nikos Kostoulas authored Dec 6, 2019
2 parents 20271c8 + f9967a4 commit c9f0833
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 3 additions & 2 deletions attestation/attestservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (s *AttestService) stateInitUnconfirmed(unconfirmedTxid chainhash.Hash) {
//set fee to unconfirmed tx's fee
feePerByte := int(walletTx.Fee*float64(Coin)) / s.attestation.Tx.SerializeSize() // fee in satoshis / tx size
s.attester.Fees.setCurrentFee(feePerByte)
isFeeBumped = false // in case we bumped fees but then attestation creation/signing/sending failed
}

// part of AStateInit
Expand Down Expand Up @@ -420,8 +421,8 @@ func (s *AttestService) doStateNewAttestation() {
txPreImage.Serialize(&txBytesBuffer)
txPreImageBytes = append(txPreImageBytes, txBytesBuffer.Bytes())
}
s.signer.SendTxPreImages(txPreImageBytes)
s.signer.ReSubscribe()
s.signer.SendTxPreImages(txPreImageBytes)

s.state = AStateSignAttestation // update attestation state
attestDelay = ATimeSigs // add sigs waiting time
Expand Down Expand Up @@ -578,8 +579,8 @@ func (s *AttestService) doStateHandleUnconfirmed() {
txPreImage.Serialize(&txBytesBuffer)
txPreImageBytes = append(txPreImageBytes, txBytesBuffer.Bytes())
}
s.signer.SendTxPreImages(txPreImageBytes)
s.signer.ReSubscribe()
s.signer.SendTxPreImages(txPreImageBytes)

s.state = AStateSignAttestation // update attestation state
attestDelay = ATimeSigs // add sigs waiting time
Expand Down
22 changes: 13 additions & 9 deletions attestation/attestservice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,16 +1034,20 @@ func TestAttestService_FailureHandleUnconfirmed(t *testing.T) {
// Test AStateHandleUnconfirmed -> AStateSignAttestation
verifyStateHandleUnconfirmedToSignAttestation(t, attestService)

// failure - re init attestation service with restart
attestService = NewAttestService(nil, nil, server, NewAttestSignerFake([]*confpkg.Config{config}), config)
attestService.attester.Fees.ResetFee(true)
// Test AStateInit -> AStateAwaitConfirmation
verifyStateInitToAwaitConfirmation(t, attestService, config, latestCommitment, txid)
// test multiple ways for this to fail; either through restart or inner state failure
if i != 2 {
// failure - re init attestation service from inner state failure
attestService.state = AStateInit
// Test AStateInit -> AStateAwaitConfirmation
verifyStateInitToAwaitConfirmation(t, attestService, config, latestCommitment, txid)
} else {
// failure - re init attestation service with restart
attestService = NewAttestService(nil, nil, server, NewAttestSignerFake([]*confpkg.Config{config}), config)
attestService.attester.Fees.ResetFee(true)
// Test AStateInit -> AStateAwaitConfirmation
verifyStateInitToAwaitConfirmation(t, attestService, config, latestCommitment, txid)
}

// failure - re init attestation service from inner state failure
attestService.state = AStateInit
// Test AStateInit -> AStateAwaitConfirmation
verifyStateInitToAwaitConfirmation(t, attestService, config, latestCommitment, txid)
// set confirm time back to test what happens in handle unconfirmed case
confirmTime = confirmTime.Add(-DefaultATimeHandleUnconfirmed)

Expand Down
2 changes: 1 addition & 1 deletion test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
"mainstay/clients"
confpkg "mainstay/config"
"mainstay/db"
"mainstay/models"
"mainstay/log"
"mainstay/models"
)

// For regtest attestation demonstration
Expand Down

0 comments on commit c9f0833

Please sign in to comment.