Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sc-7148 fix expired transaction issue #103

Merged
merged 2 commits into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 36 additions & 24 deletions lib/python/rvaspy/rvaspy/api_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 17 additions & 4 deletions pkg/rvasp/async.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,23 @@ txloop:
continue txloop
}

// Acknowledge the transaction with the originator
if err = s.acknowledgeTransaction(tx); err != nil {
log.Warn().Err(err).Uint("id", tx.ID).Msg("could not acknowledge transaction")
tx.SetState(pb.TransactionState_FAILED)
switch tx.State {
case pb.TransactionState_PENDING_SENT, pb.TransactionState_PENDING_ACKNOWLEDGED:
// We are the beneficiary, so acknowledge the pending transaction with the
// originator
if err = s.acknowledgeTransaction(tx); err != nil {
log.Warn().Err(err).Uint("id", tx.ID).Msg("could not acknowledge transaction")
tx.SetState(pb.TransactionState_FAILED)
}
case pb.TransactionState_PENDING_RECEIVED:
// We are the originator, so send a new transfer to the beneficiary to
// continue the async handshake
if err = s.parent.continueAsync(tx); err != nil {
log.Warn().Err(err).Uint("id", tx.ID).Msg("could not send transaction")
tx.SetState(pb.TransactionState_FAILED)
}
default:
log.Error().Uint("id", tx.ID).Str("state", tx.StateString).Msg("unexpected transaction state")
}

// Save the updated transaction in the database
Expand Down
6 changes: 3 additions & 3 deletions pkg/rvasp/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (d *DB) LookupIdentity(walletAddress string) *gorm.DB {

// LookupPending returns the pending transactions.
func (d *DB) LookupPending() *gorm.DB {
return d.Query().Where("state in (?, ?)", pb.TransactionState_PENDING_SENT, pb.TransactionState_PENDING_ACKNOWLEDGED)
return d.Query().Where("state in (?, ?, ?)", pb.TransactionState_PENDING_SENT, pb.TransactionState_PENDING_RECEIVED, pb.TransactionState_PENDING_ACKNOWLEDGED)
}

// LookupTransaction by envelope ID.
Expand Down Expand Up @@ -152,8 +152,8 @@ func (d *DB) MakeTransaction(originator string, beneficiary string) (*Transactio
Envelope: uuid.New().String(),
Originator: originatorIdentity,
Beneficiary: beneficiaryIdentity,
State: pb.TransactionState_AWAITING,
StateString: pb.TransactionState_AWAITING.String(),
State: pb.TransactionState_AWAITING_REPLY,
StateString: pb.TransactionState_AWAITING_REPLY.String(),
Timestamp: time.Now(),
Vasp: d.vasp,
}, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/rvasp/db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ func (s *dbTestSuite) TestLookupPending() {
id := s.db.GetVASP().ID

// Transaction lookups should be limited to the configured VASP
query := regexp.QuoteMeta(`SELECT * FROM "transactions" WHERE vasp_id = $1 AND state in ($2, $3)`)
s.mock.ExpectQuery(query).WithArgs(id, pb.TransactionState_PENDING_SENT, pb.TransactionState_PENDING_ACKNOWLEDGED).WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(id))
query := regexp.QuoteMeta(`SELECT * FROM "transactions" WHERE vasp_id = $1 AND state in ($2, $3, $4)`)
s.mock.ExpectQuery(query).WithArgs(id, pb.TransactionState_PENDING_SENT, pb.TransactionState_PENDING_RECEIVED, pb.TransactionState_PENDING_ACKNOWLEDGED).WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(id))

var transaction db.Transaction
tx := s.db.LookupPending().First(&transaction)
Expand Down
Loading