Skip to content

Commit

Permalink
Merge pull request #6707 from multiversx/fix-chain-simulator
Browse files Browse the repository at this point in the history
fix chain simulator
  • Loading branch information
miiu96 authored Jan 15, 2025
2 parents 545d15e + 0de4606 commit 96b260a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions node/chainSimulator/chainSimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,18 @@ func (s *simulator) incrementRoundOnAllValidators() {
// ForceChangeOfEpoch will force the change of current epoch
// This method will call the epoch change trigger and generate block till a new epoch is reached
func (s *simulator) ForceChangeOfEpoch() error {
s.mutex.Lock()
log.Info("force change of epoch")
for shardID, node := range s.nodes {
err := node.ForceChangeOfEpoch()
if err != nil {
s.mutex.Unlock()
return fmt.Errorf("force change of epoch shardID-%d: error-%w", shardID, err)
}
}

epoch := s.nodes[core.MetachainShardId].GetProcessComponents().EpochStartTrigger().Epoch()
s.mutex.Unlock()

return s.GenerateBlocksUntilEpochIsReached(int32(epoch + 1))
}
Expand Down
18 changes: 13 additions & 5 deletions node/chainSimulator/components/syncedMessenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,21 @@ func (messenger *syncedMessenger) receive(fromConnectedPeer core.PeerID, message
handlers := messenger.topics[message.Topic()]
messenger.mutOperation.RUnlock()

wg := &sync.WaitGroup{}
wg.Add(len(handlers))
for _, handler := range handlers {
err := handler.ProcessReceivedMessage(message, fromConnectedPeer, messenger)
if err != nil {
log.Trace("received message syncedMessenger",
"error", err, "topic", message.Topic(), "from connected peer", fromConnectedPeer.Pretty())
}
// this is needed to process all received messages on multiple go routines
go func(proc p2p.MessageProcessor, p2pMessage p2p.MessageP2P, peer core.PeerID, localWG *sync.WaitGroup) {
err := proc.ProcessReceivedMessage(p2pMessage, peer, messenger)
if err != nil {
log.Trace("received message syncedMessenger", "error", err, "topic", p2pMessage.Topic(), "from connected peer", peer.Pretty())
}

localWG.Done()
}(handler, message, fromConnectedPeer, wg)
}

wg.Wait()
}

// ProcessReceivedMessage does nothing and returns nil
Expand Down

0 comments on commit 96b260a

Please sign in to comment.