-
Notifications
You must be signed in to change notification settings - Fork 248
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
Result of tx processing returned as QueuedTxResult #537
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package transactions | ||
|
||
import "errors" | ||
|
||
var ( | ||
//ErrQueuedTxTimedOut - error transaction sending timed out | ||
ErrQueuedTxTimedOut = errors.New("transaction sending timed out") | ||
//ErrQueuedTxDiscarded - error transaction discarded | ||
ErrQueuedTxDiscarded = errors.New("transaction has been discarded") | ||
) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,16 +19,12 @@ const ( | |
) | ||
|
||
var ( | ||
// ErrQueuedTxExist - transaction was already enqueued | ||
ErrQueuedTxExist = errors.New("transaction already exist in queue") | ||
//ErrQueuedTxIDNotFound - error transaction hash not found | ||
ErrQueuedTxIDNotFound = errors.New("transaction hash not found") | ||
//ErrQueuedTxTimedOut - error transaction sending timed out | ||
ErrQueuedTxTimedOut = errors.New("transaction sending timed out") | ||
//ErrQueuedTxDiscarded - error transaction discarded | ||
ErrQueuedTxDiscarded = errors.New("transaction has been discarded") | ||
//ErrQueuedTxInProgress - error transaction in progress | ||
//ErrQueuedTxInProgress - error transaction is in progress | ||
ErrQueuedTxInProgress = errors.New("transaction is in progress") | ||
//ErrQueuedTxAlreadyProcessed - error transaction has already processed | ||
ErrQueuedTxAlreadyProcessed = errors.New("transaction has been already processed") | ||
//ErrInvalidCompleteTxSender - error transaction with invalid sender | ||
ErrInvalidCompleteTxSender = errors.New("transaction can only be completed by the same account which created it") | ||
) | ||
|
@@ -133,15 +129,18 @@ func (q *TxQueue) Reset() { | |
// Enqueue enqueues incoming transaction | ||
func (q *TxQueue) Enqueue(tx *common.QueuedTx) error { | ||
log.Info(fmt.Sprintf("enqueue transaction: %s", tx.ID)) | ||
if (tx.Hash != gethcommon.Hash{} || tx.Err != nil) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I remember when it can happen that a transaction is queued multiple times. It's possible from the interface. We should check if the given transaction is not in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you meant transaction managers interface, right? not one that is used by react, i don't see how react can set ID for queued transaction |
||
return ErrQueuedTxAlreadyProcessed | ||
q.mu.RLock() | ||
if _, ok := q.transactions[tx.ID]; ok { | ||
q.mu.RUnlock() | ||
return ErrQueuedTxExist | ||
} | ||
q.mu.RUnlock() | ||
|
||
log.Info("before enqueueTicker") | ||
// we can't hold a lock in this part | ||
log.Debug("notifying eviction loop") | ||
q.enqueueTicker <- struct{}{} // notify eviction loop that we are trying to insert new item | ||
log.Info("before evictableIDs") | ||
q.evictableIDs <- tx.ID // this will block when we hit DefaultTxQueueCap | ||
log.Info("after evictableIDs") | ||
q.evictableIDs <- tx.ID // this will block when we hit DefaultTxQueueCap | ||
log.Debug("notified eviction loop") | ||
|
||
q.mu.Lock() | ||
q.transactions[tx.ID] = tx | ||
|
@@ -204,17 +203,15 @@ func (q *TxQueue) Done(id common.QueuedTxID, hash gethcommon.Hash, err error) er | |
|
||
func (q *TxQueue) done(tx *common.QueuedTx, hash gethcommon.Hash, err error) { | ||
delete(q.inprogress, tx.ID) | ||
tx.Err = err | ||
// hash is updated only if err is nil, but transaction is not removed from a queue | ||
if err == nil { | ||
q.transactions[tx.ID].Result <- common.TransactionResult{Hash: hash, Error: err} | ||
q.remove(tx.ID) | ||
tx.Hash = hash | ||
close(tx.Done) | ||
return | ||
} | ||
if _, transient := transientErrs[err.Error()]; !transient { | ||
q.transactions[tx.ID].Result <- common.TransactionResult{Error: err} | ||
q.remove(tx.ID) | ||
close(tx.Done) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see now that
ErrorCode
was defined as astring
in a struct. This is a nice solution!