ceremonyclient/node/consensus/ceremony/execution_registration.go

89 lines
1.8 KiB
Go
Raw Normal View History

2023-09-25 02:43:35 +00:00
package ceremony
import (
"go.uber.org/zap"
"source.quilibrium.com/quilibrium/monorepo/node/execution"
)
func (e *CeremonyDataClockConsensusEngine) RegisterExecutor(
exec execution.ExecutionEngine,
frame uint64,
) <-chan error {
logger := e.logger.With(zap.String("execution_engine_name", exec.GetName()))
logger.Info("registering execution engine")
errChan := make(chan error)
go func() {
for {
2024-02-13 07:04:56 +00:00
masterFrame, err := e.masterTimeReel.Head()
if err != nil {
panic(err)
}
2023-09-25 02:43:35 +00:00
logger.Info(
"awaiting frame",
2024-02-13 07:04:56 +00:00
zap.Uint64("current_frame", masterFrame.FrameNumber),
2023-09-25 02:43:35 +00:00
zap.Uint64("target_frame", frame),
)
2024-02-13 07:04:56 +00:00
newFrame := masterFrame.FrameNumber
2023-09-25 02:43:35 +00:00
if newFrame >= frame {
logger.Info(
"injecting execution engine at frame",
zap.Uint64("current_frame", newFrame),
)
e.engineMx.Lock()
e.executionEngines[exec.GetName()] = exec
e.engineMx.Unlock()
errChan <- nil
break
}
}
}()
return errChan
}
func (e *CeremonyDataClockConsensusEngine) UnregisterExecutor(
name string,
frame uint64,
force bool,
) <-chan error {
logger := e.logger.With(zap.String("execution_engine_name", name))
logger.Info("unregistering execution engine")
errChan := make(chan error)
go func() {
for {
2024-02-13 07:04:56 +00:00
masterFrame, err := e.masterTimeReel.Head()
if err != nil {
panic(err)
}
2023-09-25 02:43:35 +00:00
logger.Info(
"awaiting frame",
2024-02-13 07:04:56 +00:00
zap.Uint64("current_frame", masterFrame.FrameNumber),
2023-09-25 02:43:35 +00:00
zap.Uint64("target_frame", frame),
)
2024-02-13 07:04:56 +00:00
newFrame := masterFrame.FrameNumber
2023-09-25 02:43:35 +00:00
if newFrame >= frame {
logger.Info(
"removing execution engine at frame",
zap.Uint64("current_frame", newFrame),
)
e.engineMx.Lock()
delete(e.executionEngines, name)
e.engineMx.Unlock()
errChan <- nil
break
}
}
}()
return errChan
}