prysm-pulse/sharding/notary/service.go
Raul Jordan 0f27660b18 sharding: using eth leveldb, interface mismatch
Former-commit-id: 127630fadb68deff3418e499f303f7eab16e775f [formerly 20bf39d9d62f72857512b505cfac7e122002c4ab]
Former-commit-id: d3baf1deac782fa9ee4bcceae658723b65d1b08d
2018-05-22 14:49:59 -04:00

53 lines
1.5 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"
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 {
node node.Node
shardDB sharding.ShardBackend
}
// NewNotary creates a new notary instance.
func NewNotary(ctx *cli.Context, 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
}