-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6612 from multiversx/heartbeats-chain-simulator
Heartbeats chain simulator
- Loading branch information
Showing
13 changed files
with
249 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package heartbeat | ||
|
||
import ( | ||
"github.com/multiversx/mx-chain-core-go/core/check" | ||
"github.com/multiversx/mx-chain-go/factory" | ||
"github.com/multiversx/mx-chain-go/heartbeat" | ||
) | ||
|
||
type heartBeatComponents struct { | ||
monitor factory.HeartbeatV2Monitor | ||
} | ||
|
||
// NewSyncedHeartbeatComponents will create a new instance of heartbeat components | ||
func NewSyncedHeartbeatComponents(monitor factory.HeartbeatV2Monitor) (factory.HeartbeatV2ComponentsHandler, error) { | ||
if check.IfNil(monitor) { | ||
return nil, heartbeat.ErrNilHeartbeatMonitor | ||
} | ||
|
||
return &heartBeatComponents{ | ||
monitor: monitor, | ||
}, nil | ||
} | ||
|
||
// Create will do nothing | ||
func (h *heartBeatComponents) Create() error { | ||
return nil | ||
} | ||
|
||
// Close will do nothing | ||
func (h *heartBeatComponents) Close() error { | ||
return nil | ||
} | ||
|
||
// CheckSubcomponents will do nothing | ||
func (h *heartBeatComponents) CheckSubcomponents() error { | ||
return nil | ||
} | ||
|
||
// String will return a string | ||
func (h *heartBeatComponents) String() string { | ||
return "heartBeat" | ||
} | ||
|
||
// Monitor will return the monitor | ||
func (h *heartBeatComponents) Monitor() factory.HeartbeatV2Monitor { | ||
return h.monitor | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (h *heartBeatComponents) IsInterfaceNil() bool { | ||
return h == nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package heartbeat | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/multiversx/mx-chain-go/heartbeat/data" | ||
) | ||
|
||
type heartbeatMonitor struct { | ||
heartbeats []data.PubKeyHeartbeat | ||
mutex sync.RWMutex | ||
} | ||
|
||
// NewHeartbeatMonitor will create a new instance of heartbeat monitor | ||
func NewHeartbeatMonitor() *heartbeatMonitor { | ||
return &heartbeatMonitor{ | ||
heartbeats: make([]data.PubKeyHeartbeat, 0), | ||
} | ||
} | ||
|
||
// GetHeartbeats will return the heartbeats | ||
func (hm *heartbeatMonitor) GetHeartbeats() []data.PubKeyHeartbeat { | ||
hm.mutex.RLock() | ||
defer hm.mutex.RUnlock() | ||
|
||
return hm.heartbeats | ||
} | ||
|
||
// SetHeartbeats will set the provided heartbeats | ||
func (hm *heartbeatMonitor) SetHeartbeats(heartbeats []data.PubKeyHeartbeat) { | ||
hm.mutex.Lock() | ||
hm.heartbeats = heartbeats | ||
hm.mutex.Unlock() | ||
} | ||
|
||
// IsInterfaceNil returns true if there is no value under the interface | ||
func (hm *heartbeatMonitor) IsInterfaceNil() bool { | ||
return nil == hm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.