diff --git a/attestation/attestservice.go b/attestation/attestservice.go index fb5e0bf..19cf0e0 100644 --- a/attestation/attestservice.go +++ b/attestation/attestservice.go @@ -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 @@ -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 @@ -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 diff --git a/attestation/attestservice_test.go b/attestation/attestservice_test.go index 7f63c8f..7180752 100644 --- a/attestation/attestservice_test.go +++ b/attestation/attestservice_test.go @@ -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) diff --git a/test/test.go b/test/test.go index c6790f8..80b737b 100644 --- a/test/test.go +++ b/test/test.go @@ -15,8 +15,8 @@ import ( "mainstay/clients" confpkg "mainstay/config" "mainstay/db" - "mainstay/models" "mainstay/log" + "mainstay/models" ) // For regtest attestation demonstration