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/internal/utils/crosslinks/crosslinks.go

46 lines
1.5 KiB

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
package crosslinks
import (
"sync/atomic"
"github.com/harmony-one/harmony/core/types"
)
// Crosslinks is helper for processing crosslinks. It has meaning only for shards.
type Crosslinks struct {
// This number stores value we have already sent.
// It can be ahead of CrosslinkHeartbeat.LatestContinuousBlockNum, because processing of crosslink takes some time.
latestSentCrosslinkBlockNumber uint64
// Latest received valid heartbeat signal.
lastKnownCrosslinkHeartbeatSignal atomic.Value
}
// New creates new Crosslinks.
func New() *Crosslinks {
return &Crosslinks{}
}
// LatestSentCrosslinkBlockNumber returns last set value for crosslink block number or zero if not.
func (a *Crosslinks) LatestSentCrosslinkBlockNumber() uint64 {
return atomic.LoadUint64(&a.latestSentCrosslinkBlockNumber)
}
// SetLatestSentCrosslinkBlockNumber sets last crosslink block number.
func (a *Crosslinks) SetLatestSentCrosslinkBlockNumber(number uint64) {
atomic.StoreUint64(&a.latestSentCrosslinkBlockNumber, number)
}
// LastKnownCrosslinkHeartbeatSignal returns last set value for heartbeat or nil if not.
func (a *Crosslinks) LastKnownCrosslinkHeartbeatSignal() *types.CrosslinkHeartbeat {
val := a.lastKnownCrosslinkHeartbeatSignal.Load()
if val == nil {
return nil
}
return val.(*types.CrosslinkHeartbeat)
}
// SetLastKnownCrosslinkHeartbeatSignal sets last known heartbeat.
func (a *Crosslinks) SetLastKnownCrosslinkHeartbeatSignal(signal *types.CrosslinkHeartbeat) {
a.lastKnownCrosslinkHeartbeatSignal.Store(signal)
}