prysm-pulse/sharding/notary/service.go
Terence Tsao 75015adc8a sharding: use shardConfig across shard codebase
Former-commit-id: a1a8597ff0d5249056feed2f1f888d46b35eccda [formerly 4da30c5de1366f140374410ff700043a778e9f97]
Former-commit-id: 9125d61ab20e9a6cedc3f63f69b6bdd152687190
2018-06-12 16:03:20 -07:00

48 lines
1.4 KiB
Go

// Package notary defines all relevant functionality for a Notary actor
// within a sharded Ethereum blockchain.
package notary
import (
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/sharding"
"github.com/ethereum/go-ethereum/sharding/mainchain"
"github.com/ethereum/go-ethereum/sharding/params"
)
// 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 {
config *params.ShardConfig
smcClient *mainchain.SMCClient
shardp2p sharding.ShardP2P
shardChainDb ethdb.Database
}
// NewNotary creates a new notary instance.
func NewNotary(config *params.ShardConfig, smcClient *mainchain.SMCClient, shardp2p sharding.ShardP2P, shardChainDb ethdb.Database) (*Notary, error) {
return &Notary{config, smcClient, shardp2p, shardChainDb}, 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
// are blocking.
if n.smcClient.DepositFlag() {
if err := joinNotaryPool(n.config, n.smcClient); err != nil {
return err
}
}
return subscribeBlockHeaders(n.smcClient)
}
// Stop the main loop for notarizing collations.
func (n *Notary) Stop() error {
log.Info("Stopping notary service")
return nil
}