Skip to content

Commit

Permalink
go/executor/node: ensure correct state before publishing a message
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrus committed Sep 30, 2020
1 parent 007ccf6 commit a780b94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .changelog/3342.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
go/executor/node: ensure correct state before publishing a message
40 changes: 20 additions & 20 deletions go/worker/compute/executor/committee/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,26 @@ func (n *Node) Dispatch(batch transaction.RawBatch) error {
return fmt.Errorf("failed to sign txn scheduler batch: %w", err)
}

n.commonNode.CrossNode.Lock()
defer n.commonNode.CrossNode.Unlock()

// If we are not waiting for a batch, don't do anything.
if _, ok := n.state.(StateWaitingForBatch); !ok {
n.logger.Error("new state since started the dispatch",
"state", n.state,
)
return errIncorrectState
}

// Ensure we are still in the same round as when we started the dispatch.
if lastHeader.Round != n.commonNode.CurrentBlock.Header.Round {
n.logger.Error("new round since started the dispatch",
"expected_round", lastHeader.Round,
"round", n.commonNode.CurrentBlock.Header.Round,
)
return errSeenNewerBlock
}

n.logger.Debug("dispatching a new batch proposal",
"io_root", ioRoot,
"num_txs", len(batch),
Expand All @@ -886,26 +906,6 @@ func (n *Node) Dispatch(batch transaction.RawBatch) error {
crash.Here(crashPointBatchPublishAfter)
spanPublish.Finish()

n.commonNode.CrossNode.Lock()
defer n.commonNode.CrossNode.Unlock()

// If we are not waiting for a batch, don't do anything.
if _, ok := n.state.(StateWaitingForBatch); !ok {
n.logger.Error("new state since started the dispatch",
"state", n.state,
)
return errIncorrectState
}

// Ensure we are still in the same round as when we started the dispatch.
if lastHeader.Round != n.commonNode.CurrentBlock.Header.Round {
n.logger.Error("new round since started the dispatch",
"expected_round", lastHeader.Round,
"round", n.commonNode.CurrentBlock.Header.Round,
)
return errSeenNewerBlock
}

// Also process the batch locally.
n.handleInternalBatchLocked(
batchSpanCtx,
Expand Down

0 comments on commit a780b94

Please sign in to comment.