From fc7d30ac09230e4826a88c98cea4d979528d5653 Mon Sep 17 00:00:00 2001 From: nkostoulas Date: Fri, 6 Dec 2019 12:19:14 +0000 Subject: [PATCH 1/2] Resubscribe before sending tx pre images --- attestation/attestservice.go | 4 ++-- test/test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/attestation/attestservice.go b/attestation/attestservice.go index fb5e0bf..3a18820 100644 --- a/attestation/attestservice.go +++ b/attestation/attestservice.go @@ -420,8 +420,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 +578,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/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 From f9967a42a4e4f12c789d617885bec490904786f3 Mon Sep 17 00:00:00 2001 From: nkostoulas Date: Fri, 6 Dec 2019 14:23:01 +0000 Subject: [PATCH 2/2] Reset bumpFee flag if initializing from an unconfirmed tx --- attestation/attestservice.go | 1 + attestation/attestservice_test.go | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/attestation/attestservice.go b/attestation/attestservice.go index 3a18820..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 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)