mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 11:11:20 +00:00
1ddb19bba6
sharding: create a syncer and a simulator package Former-commit-id: b392885510ba5a96e61278cbbe2c0ec6f9722ee8 [formerly 3a435eaf6805d02beae55656f155b2c3a66ee663] Former-commit-id: 0f6f3f2053ae77711e2072848b727b0dc9b92276
47 lines
1.4 KiB
Go
47 lines
1.4 KiB
Go
// Package observer launches a service attached to the sharding node
|
|
// that simply observes activity across the sharded Ethereum network.
|
|
package observer
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"math/big"
|
|
|
|
"github.com/ethereum/go-ethereum/ethdb"
|
|
"github.com/ethereum/go-ethereum/log"
|
|
"github.com/ethereum/go-ethereum/sharding"
|
|
"github.com/ethereum/go-ethereum/sharding/p2p"
|
|
)
|
|
|
|
// Observer holds functionality required to run an observer service
|
|
// in a sharded system. Must satisfy the Service interface defined in
|
|
// sharding/service.go.
|
|
type Observer struct {
|
|
p2p *p2p.Server
|
|
shard *sharding.Shard
|
|
ctx context.Context
|
|
cancel context.CancelFunc
|
|
}
|
|
|
|
// NewObserver creates a struct instance of a observer service,
|
|
// it will have access to a p2p server and a shardChainDb.
|
|
func NewObserver(p2p *p2p.Server, shardChainDB ethdb.Database, shardID int) (*Observer, error) {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
shard := sharding.NewShard(big.NewInt(int64(shardID)), shardChainDB)
|
|
return &Observer{p2p, shard, ctx, cancel}, nil
|
|
}
|
|
|
|
// Start the main loop for observer service.
|
|
func (o *Observer) Start() {
|
|
log.Info(fmt.Sprintf("Starting observer service"))
|
|
}
|
|
|
|
// Stop the main loop for observer service.
|
|
func (o *Observer) Stop() error {
|
|
// Triggers a cancel call in the service's context which shuts down every goroutine
|
|
// in this service.
|
|
defer o.cancel()
|
|
log.Info(fmt.Sprintf("Stopping observer service"))
|
|
return nil
|
|
}
|