2018-05-22 11:53:15 +00:00
|
|
|
package notary
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
2018-05-22 12:47:35 +00:00
|
|
|
"github.com/ethereum/go-ethereum/sharding/node"
|
2018-05-22 11:53:15 +00:00
|
|
|
cli "gopkg.in/urfave/cli.v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2018-05-22 12:47:35 +00:00
|
|
|
node node.Node
|
2018-05-22 11:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewNotary creates a new notary instance.
|
2018-05-22 12:47:35 +00:00
|
|
|
func NewNotary(ctx *cli.Context, node node.Node) (*Notary, error) {
|
|
|
|
return &Notary{node}, nil
|
2018-05-22 11:53:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start the main routine for a notary.
|
|
|
|
func (n *Notary) Start() error {
|
2018-05-22 12:47:35 +00:00
|
|
|
log.Info("Starting notary service")
|
2018-05-22 11:53:15 +00:00
|
|
|
|
2018-05-22 12:56:56 +00:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
2018-05-22 11:53:15 +00:00
|
|
|
|
2018-05-22 12:56:56 +00:00
|
|
|
return subscribeBlockHeaders(n.node)
|
2018-05-22 12:47:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Stop the main loop for notarizing collations.
|
|
|
|
func (n *Notary) Stop() error {
|
|
|
|
log.Info("Stopping notary service")
|
2018-05-22 11:53:15 +00:00
|
|
|
return nil
|
|
|
|
}
|