Skip to content

Commit

Permalink
go/runtime/scheduling/simple: Only dispatch one batch at a time
Browse files Browse the repository at this point in the history
Since batches only get deleted after a successful dispatch, dispatching
a batch while one is in progress will duplicate transactions that were
already dispatched but not yet deleted. Note: this doesn't change
current behaviour as the executor already enforces this. The added check only
prevents potential future misuse of the scheduler.
  • Loading branch information
ptrus committed Oct 19, 2020
1 parent 66c7069 commit e2695b4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion go/runtime/scheduling/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package simple

import (
"fmt"
"sync/atomic"

"github.com/oasisprotocol/oasis-core/go/common/crypto/hash"
"github.com/oasisprotocol/oasis-core/go/common/logging"
Expand All @@ -26,10 +27,17 @@ type scheduler struct {

incomingQueue txpoolApi.TxPool

dispatcher api.TransactionDispatcher
dispatchInProgress uint32
dispatcher api.TransactionDispatcher
}

func (s *scheduler) scheduleBatch(force bool) error {
if !atomic.CompareAndSwapUint32(&s.dispatchInProgress, 0, 1) {
// Dispatch already in progress.
return nil
}
defer atomic.StoreUint32(&s.dispatchInProgress, 0)

batch := s.incomingQueue.GetBatch(force)
if len(batch) > 0 {
// Try to dispatch batch.
Expand Down

0 comments on commit e2695b4

Please sign in to comment.