mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
1bd464aade
Former-commit-id: ec3595f6111b15e2ea6a3ecd35e6a3934314a662 [formerly df7289f224ce6bc35ef9dd2ec6e129662aad3489] Former-commit-id: ae8e1f1b95b113767cb3fa0e0835e59043ceca32
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
// Package notary defines all relevant functionality for a Notary actor
|
|
// within a sharded Ethereum blockchain.
|
|
package notary
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/sharding/mainchain"
|
|
"github.com/ethereum/go-ethereum/sharding/p2p"
|
|
"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.Config
|
|
smcClient *mainchain.SMCClient
|
|
p2p *p2p.Server
|
|
shardChainDb ethdb.Database
|
|
}
|
|
|
|
// NewNotary creates a new notary instance.
|
|
func NewNotary(config *params.Config, smcClient *mainchain.SMCClient, p2p *p2p.Server, shardChainDb ethdb.Database) (*Notary, error) {
|
|
return &Notary{config, smcClient, p2p, shardChainDb}, nil
|
|
}
|
|
|
|
// Start the main routine for a notary.
|
|
func (n *Notary) Start() {
|
|
log.Info("Starting notary service")
|
|
go n.notarizeCollations()
|
|
}
|
|
|
|
// Stop the main loop for notarizing collations.
|
|
func (n *Notary) Stop() error {
|
|
log.Info("Stopping notary service")
|
|
return nil
|
|
}
|
|
|
|
func (n *Notary) notarizeCollations() {
|
|
// 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 {
|
|
log.Error(fmt.Sprintf("Could not fetch current block number: %v", err))
|
|
return
|
|
}
|
|
}
|
|
|
|
if err := subscribeBlockHeaders(n.smcClient); err != nil {
|
|
log.Error(fmt.Sprintf("Could not fetch current block number: %v", err))
|
|
return
|
|
}
|
|
}
|