The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/api/service/crosslink_sending/service.go

61 lines
1.1 KiB

package crosslink_sending
import (
"github.com/harmony-one/harmony/core"
"github.com/harmony-one/harmony/shard"
)
type broadcast interface {
BroadcastCrosslinkHeartbeatSignalFromBeaconToShards()
BroadcastCrossLinkFromShardsToBeacon()
}
type Service struct {
node broadcast
bc core.BlockChain
ch chan core.ChainEvent
closeCh chan struct{}
beacon bool
}
func New(node broadcast, bc core.BlockChain) *Service {
return &Service{
node: node,
bc: bc,
ch: make(chan core.ChainEvent, 1),
closeCh: make(chan struct{}),
beacon: bc.ShardID() == shard.BeaconChainShardID,
}
}
// Start starts service.
func (s *Service) Start() error {
s.bc.SubscribeChainEvent(s.ch)
go s.run()
return nil
}
func (s *Service) run() {
for {
select {
case _, ok := <-s.ch:
if !ok {
return
}
if s.beacon {
go s.node.BroadcastCrosslinkHeartbeatSignalFromBeaconToShards()
} else {
Epoch syncing - syncing only epoch blocks. (#4070) * Epoch syncing - syncing only epoch blocks. * Fix go test, added command to run. * Block signature validation. * Support getting block by height. * Fix to compile. * Http method. * Generate fix. * Install protoc-gen-go-grpc. * Fix sync, additional timeouts, fix epoch. * Chain behaviour options, optional state validation on blockchain initialization. * Added limit to avoid abuse, small fixes. * Fix duplicate code. * Fix isInSyn. * Fix method call. * Removed additional block sending. * Fix in sync. * Code clean up. * Fix beacon chain func. * Return back Beaconchain. * Fix sending only epoch blocks. * Fix failed startup with validator. * Increase recv message size. * Remove peer. * Add logs. * Add logs. * Fix msgf call. * Epoch syncing - syncing only epoch blocks. * Block signature validation. * Fix sync, additional timeouts, fix epoch. * Chain behaviour options, optional state validation on blockchain initialization. * Support getting block by height. * Http method. * Fix duplicate code. * Fix isInSyn. * Added limit to avoid abuse, small fixes. * Fix method call. * Removed additional block sending. * Fix in sync. * Small fix. * Code clean up. * Fix beacon chain func. * Return back Beaconchain. * Fix sending only epoch blocks. * Fix failed startup with validator. * Increase recv message size. * Remove peer. * Add logs. * Fix msgf call. * Sending crosslinks from beacon to non-beacon chains. * Receiving crosslinks. * Broadcast. * Fix comment. * Crosslink signal. * Crosslink hardbeat signal receiving. * Sending crosslinks from beacon to non-beacon chains. * Sending crosslinks from beacon to non-beacon chains. * Broadcast. * Fix comment. * Crosslink signal. * Crosslink signal. * Add comment to run tests. * Fix comments. * Fix comments. * Fix review comments. * Updated with last crosslink heart beat signal. * Merged crosslink signal. * Clean up code. * Add logs for cl debug. * Stop iterate on receiving result. * Add logs. * Fix in sync check. * Fix reconnect problems. * Fix tests and reduce dependency. * Updated with main. * Fix review comments. * Changed to compare epochs. * Fix crosslinks usage. * Fix initialization. * Epoch chain implementation. * Legacy sync by default. * Revert "Legacy sync by default." This reverts commit 5fa6ce002a16699cc3ca75bdd40b068dbe6cefb6. * Epoch sync for downloader. * Build docker image while tests. * Fix paths. * Updated travis. * Review improvements. Co-authored-by: Konstantin <k.potapov@softpro.com>
2 years ago
go s.node.BroadcastCrossLinkFromShardsToBeacon()
}
case <-s.closeCh:
return
}
}
}
// Stop stops service.
func (s *Service) Stop() error {
close(s.closeCh)
return nil
}