mirror of
https://github.com/aljazceru/ark.git
synced 2025-12-18 12:44:19 +01:00
Fixes (#107)
This commit is contained in:
committed by
GitHub
parent
9944a3cc48
commit
bcd66d7ae7
@@ -65,8 +65,8 @@ func (c *Config) Validate() error {
|
||||
if !supportedScanners.supports(c.BlockchainScannerType) {
|
||||
return fmt.Errorf("blockchain scanner type not supported, please select one of: %s", supportedScanners)
|
||||
}
|
||||
if c.RoundInterval < 5 {
|
||||
return fmt.Errorf("invalid round interval, must be at least 5 seconds")
|
||||
if c.RoundInterval < 2 {
|
||||
return fmt.Errorf("invalid round interval, must be at least 2 seconds")
|
||||
}
|
||||
if c.Network.Name != "liquid" && c.Network.Name != "testnet" {
|
||||
return fmt.Errorf("invalid network, must be either liquid or testnet")
|
||||
|
||||
@@ -42,7 +42,7 @@ var (
|
||||
RoundLifetime = "ROUND_LIFETIME"
|
||||
|
||||
defaultDatadir = common.AppDataDir("arkd", false)
|
||||
defaultRoundInterval = 60
|
||||
defaultRoundInterval = 10
|
||||
defaultPort = 6000
|
||||
defaultDbType = "badger"
|
||||
defaultSchedulerType = "gocron"
|
||||
|
||||
@@ -20,7 +20,7 @@ type eventsDTO struct {
|
||||
|
||||
type eventRepository struct {
|
||||
store *badgerhold.Store
|
||||
lock *sync.RWMutex
|
||||
lock *sync.Mutex
|
||||
chUpdates chan *domain.Round
|
||||
handler func(round *domain.Round)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func NewRoundEventRepository(config ...interface{}) (dbtypes.EventStore, error)
|
||||
return nil, fmt.Errorf("failed to open round events store: %s", err)
|
||||
}
|
||||
chEvents := make(chan *domain.Round)
|
||||
lock := &sync.RWMutex{}
|
||||
lock := &sync.Mutex{}
|
||||
repo := &eventRepository{store, lock, chEvents, nil}
|
||||
go repo.listen()
|
||||
return repo, nil
|
||||
@@ -137,18 +137,22 @@ func (r *eventRepository) upsert(
|
||||
}
|
||||
|
||||
func (r *eventRepository) listen() {
|
||||
for updatedRound := range r.chUpdates {
|
||||
r.lock.RLock()
|
||||
if r.handler != nil {
|
||||
r.handler(updatedRound)
|
||||
}
|
||||
r.lock.RUnlock()
|
||||
for round := range r.chUpdates {
|
||||
r.runHandler(round)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *eventRepository) publishEvents(events []domain.RoundEvent) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
round := domain.NewRoundFromEvents(events)
|
||||
r.chUpdates <- round
|
||||
}
|
||||
|
||||
func (r *eventRepository) runHandler(round *domain.Round) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if r.handler == nil {
|
||||
return
|
||||
}
|
||||
r.handler(round)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user