mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
08eb16eecb
Former-commit-id: 2b402c6cce64f0c38d6d3ce48b4818c839bec19d [formerly e3ea64a3e937d89f586af617f3b899bb950e30b7] Former-commit-id: ddd9e507e1e49758152ddf6e8827864df700dad7
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package notary
|
|
|
|
import (
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/sharding"
|
|
"github.com/ethereum/go-ethereum/sharding/database"
|
|
"github.com/ethereum/go-ethereum/sharding/node"
|
|
)
|
|
|
|
// Notary holds functionality required to run a collation notary
|
|
// in a sharded system. Must satisfy the Service interface defined in
|
|
// sharding/service.go.
|
|
type Notary struct {
|
|
node node.Node
|
|
shardDB sharding.ShardBackend
|
|
}
|
|
|
|
// NewNotary creates a new notary instance.
|
|
func NewNotary(node node.Node) (*Notary, error) {
|
|
// Initializes a shardDB that writes to disk at /path/to/datadir/shardchaindata.
|
|
// This DB can be used by the Notary service to create Shard struct
|
|
// instances.
|
|
shardDB, err := database.NewShardDB(node.Context(), "shardchaindata")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &Notary{node, shardDB}, nil
|
|
}
|
|
|
|
// Start the main routine for a notary.
|
|
func (n *Notary) Start() error {
|
|
log.Info("Starting notary service")
|
|
|
|
// TODO: handle this better through goroutines. Right now, these methods
|
|
// have their own nested channels and goroutines within them. We need
|
|
// to make this as flat as possible at the Notary layer.
|
|
if n.node.DepositFlagSet() {
|
|
if err := joinNotaryPool(n.node); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return subscribeBlockHeaders(n.node)
|
|
}
|
|
|
|
// Stop the main loop for notarizing collations.
|
|
func (n *Notary) Stop() error {
|
|
log.Info("Stopping notary service")
|
|
return nil
|
|
}
|