ceremonyclient/node/app/node.go

98 lines
2.1 KiB
Go
Raw Normal View History

2023-09-03 23:47:09 +00:00
package app
import (
"errors"
"go.uber.org/zap"
2023-09-03 23:47:09 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/consensus"
2024-03-04 03:20:24 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/consensus/master"
2023-09-03 23:47:09 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/execution"
2024-02-13 07:04:56 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/execution/intrinsics/ceremony"
2023-10-28 02:23:55 +00:00
"source.quilibrium.com/quilibrium/monorepo/node/keys"
"source.quilibrium.com/quilibrium/monorepo/node/p2p"
"source.quilibrium.com/quilibrium/monorepo/node/store"
2023-09-03 23:47:09 +00:00
)
type Node struct {
logger *zap.Logger
clockStore store.ClockStore
2023-10-28 02:23:55 +00:00
keyManager keys.KeyManager
pubSub p2p.PubSub
2023-09-03 23:47:09 +00:00
execEngines map[string]execution.ExecutionEngine
engine consensus.ConsensusEngine
}
func newNode(
logger *zap.Logger,
clockStore store.ClockStore,
2023-10-28 02:23:55 +00:00
keyManager keys.KeyManager,
pubSub p2p.PubSub,
2023-09-25 02:43:35 +00:00
ceremonyExecutionEngine *ceremony.CeremonyExecutionEngine,
2023-09-03 23:47:09 +00:00
engine consensus.ConsensusEngine,
) (*Node, error) {
if engine == nil {
return nil, errors.New("engine must not be nil")
}
execEngines := make(map[string]execution.ExecutionEngine)
2023-09-25 02:43:35 +00:00
if ceremonyExecutionEngine != nil {
execEngines[ceremonyExecutionEngine.GetName()] = ceremonyExecutionEngine
2023-09-03 23:47:09 +00:00
}
return &Node{
logger,
clockStore,
2023-10-28 02:23:55 +00:00
keyManager,
pubSub,
2023-09-03 23:47:09 +00:00
execEngines,
engine,
}, nil
}
func (n *Node) Start() {
err := <-n.engine.Start()
if err != nil {
panic(err)
}
// TODO: add config mapping to engine name/frame registration
for _, e := range n.execEngines {
n.engine.RegisterExecutor(e, 0)
}
}
func (n *Node) Stop() {
err := <-n.engine.Stop(false)
if err != nil {
panic(err)
}
}
func (n *Node) GetLogger() *zap.Logger {
return n.logger
}
func (n *Node) GetClockStore() store.ClockStore {
return n.clockStore
}
2023-10-28 02:23:55 +00:00
func (n *Node) GetKeyManager() keys.KeyManager {
return n.keyManager
}
func (n *Node) GetPubSub() p2p.PubSub {
return n.pubSub
}
2024-03-04 03:20:24 +00:00
func (n *Node) GetMasterClock() *master.MasterClockConsensusEngine {
return n.engine.(*master.MasterClockConsensusEngine)
}
func (n *Node) GetExecutionEngines() []execution.ExecutionEngine {
list := []execution.ExecutionEngine{}
for _, e := range n.execEngines {
list = append(list, e)
}
return list
}