This commit is contained in:
Cassandra Heart 2024-03-17 16:14:37 -05:00 committed by GitHub
parent 60afbb33b6
commit 3001611197
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 37 additions and 27 deletions

View File

@ -14,9 +14,12 @@ func GetMinimumVersion() []byte {
} }
func GetVersion() []byte { func GetVersion() []byte {
return []byte{0x01, 0x04, 0x08} return []byte{0x01, 0x04, 0x09}
} }
func GetVersionString() string { func GetVersionString() string {
return fmt.Sprintf("%d.%d.%d", GetVersion()[0], GetVersion()[1], GetVersion()[2]) return fmt.Sprintf(
"%d.%d.%d",
GetVersion()[0], GetVersion()[1], GetVersion()[2],
)
} }

View File

@ -471,7 +471,7 @@ func (e *CeremonyDataClockConsensusEngine) runLoop() {
e.frameProverTrie.FindNearest(e.provingKeyAddress).External.Key, e.frameProverTrie.FindNearest(e.provingKeyAddress).External.Key,
e.provingKeyAddress, e.provingKeyAddress,
) { ) {
e.dataTimeReel.Insert(nextFrame) e.dataTimeReel.Insert(nextFrame, false)
if err = e.publishProof(nextFrame); err != nil { if err = e.publishProof(nextFrame); err != nil {
e.logger.Error("could not publish", zap.Error(err)) e.logger.Error("could not publish", zap.Error(err))
@ -513,7 +513,7 @@ func (e *CeremonyDataClockConsensusEngine) runLoop() {
e.frameProverTrie.FindNearest(e.provingKeyAddress).External.Key, e.frameProverTrie.FindNearest(e.provingKeyAddress).External.Key,
e.provingKeyAddress, e.provingKeyAddress,
) { ) {
e.dataTimeReel.Insert(nextFrame) e.dataTimeReel.Insert(nextFrame, false)
if err = e.publishProof(nextFrame); err != nil { if err = e.publishProof(nextFrame); err != nil {
e.logger.Error("could not publish", zap.Error(err)) e.logger.Error("could not publish", zap.Error(err))

View File

@ -445,6 +445,8 @@ func (e *CeremonyDataClockConsensusEngine) sync(
e.logger.Error("error while closing connection", zap.Error(err)) e.logger.Error("error while closing connection", zap.Error(err))
} }
e.dataTimeReel.Insert(latest, false)
return latest, nil return latest, nil
} }

View File

@ -331,6 +331,6 @@ func (e *CeremonyDataClockConsensusEngine) handleClockFrameData(
zap.Uint64("frame_number", frame.FrameNumber), zap.Uint64("frame_number", frame.FrameNumber),
) )
e.dataTimeReel.Insert(frame) e.dataTimeReel.Insert(frame, isSync)
return nil return nil
} }

View File

@ -189,7 +189,7 @@ func (e *MasterClockConsensusEngine) publishProof(
zap.Uint64("frame_number", frame.FrameNumber), zap.Uint64("frame_number", frame.FrameNumber),
) )
e.masterTimeReel.Insert(frame) e.masterTimeReel.Insert(frame, false)
peers, err := e.GetMostAheadPeers() peers, err := e.GetMostAheadPeers()
if err != nil || len(peers) == 0 { if err != nil || len(peers) == 0 {

View File

@ -136,7 +136,7 @@ func (e *MasterClockConsensusEngine) collect(
break break
} }
e.masterTimeReel.Insert(frame) e.masterTimeReel.Insert(frame, false)
latest = frame latest = frame
} }
} }

View File

@ -167,7 +167,7 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
continue continue
} }
e.masterTimeReel.Insert(newFrame) e.masterTimeReel.Insert(newFrame, false)
case peerId := <-e.bandwidthTestCh: case peerId := <-e.bandwidthTestCh:
e.performBandwidthTest(peerId) e.performBandwidthTest(peerId)
} }

View File

@ -152,7 +152,7 @@ func (d *DataTimeReel) Head() (*protobufs.ClockFrame, error) {
// Insert enqueues a structurally valid frame into the time reel. If the frame // Insert enqueues a structurally valid frame into the time reel. If the frame
// is the next one in sequence, it advances the reel head forward and emits a // is the next one in sequence, it advances the reel head forward and emits a
// new frame on the new frame channel. // new frame on the new frame channel.
func (d *DataTimeReel) Insert(frame *protobufs.ClockFrame) error { func (d *DataTimeReel) Insert(frame *protobufs.ClockFrame, isSync bool) error {
if !d.running { if !d.running {
return nil return nil
} }
@ -179,13 +179,15 @@ func (d *DataTimeReel) Insert(frame *protobufs.ClockFrame) error {
d.storePending(selector, parent, distance, frame) d.storePending(selector, parent, distance, frame)
go func() { if !isSync {
d.frames <- &pendingFrame{ go func() {
selector: selector, d.frames <- &pendingFrame{
parentSelector: parent, selector: selector,
frameNumber: frame.FrameNumber, parentSelector: parent,
} frameNumber: frame.FrameNumber,
}() }
}()
}
return nil return nil
} }

View File

@ -155,7 +155,7 @@ func TestDataTimeReel(t *testing.T) {
frame, err = prover.ProveMasterClockFrame(frame, i+1, 10) frame, err = prover.ProveMasterClockFrame(frame, i+1, 10)
assert.NoError(t, err) assert.NoError(t, err)
err := m.Insert(frame) err := m.Insert(frame, false)
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -249,7 +249,7 @@ func TestDataTimeReel(t *testing.T) {
i+1, i+1,
10, 10,
) )
d.Insert(frame) d.Insert(frame, false)
} }
// 2. z-dist optimal, out of order proof submission is strictly master-frame // 2. z-dist optimal, out of order proof submission is strictly master-frame
@ -278,7 +278,7 @@ func TestDataTimeReel(t *testing.T) {
} }
for i := 9; i >= 0; i-- { for i := 9; i >= 0; i-- {
err := d.Insert(insertFrames[i]) err := d.Insert(insertFrames[i], false)
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -303,7 +303,7 @@ func TestDataTimeReel(t *testing.T) {
i+1, i+1,
10, 10,
) )
d.Insert(frame) d.Insert(frame, false)
} }
masterSelector, err := frames[25].GetSelector() masterSelector, err := frames[25].GetSelector()
@ -349,7 +349,7 @@ func TestDataTimeReel(t *testing.T) {
} }
for i := 4; i >= 0; i-- { for i := 4; i >= 0; i-- {
err := d.Insert(insertFrames[i]) err := d.Insert(insertFrames[i], false)
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -402,7 +402,7 @@ func TestDataTimeReel(t *testing.T) {
} }
for i := 9; i >= 0; i-- { for i := 9; i >= 0; i-- {
err := d.Insert(conflictFrames[i]) err := d.Insert(conflictFrames[i], false)
// force linear ordering // force linear ordering
gotime.Sleep(1 * gotime.Second) gotime.Sleep(1 * gotime.Second)
assert.NoError(t, err) assert.NoError(t, err)
@ -410,7 +410,7 @@ func TestDataTimeReel(t *testing.T) {
// Someone is honest, but running backwards: // Someone is honest, but running backwards:
for i := 9; i >= 0; i-- { for i := 9; i >= 0; i-- {
err := d.Insert(insertFrames[i]) err := d.Insert(insertFrames[i], false)
gotime.Sleep(1 * gotime.Second) gotime.Sleep(1 * gotime.Second)
assert.NoError(t, err) assert.NoError(t, err)
} }

View File

@ -114,7 +114,10 @@ func (m *MasterTimeReel) Head() (*protobufs.ClockFrame, error) {
// Insert enqueues a structurally valid frame into the time reel. If the frame // Insert enqueues a structurally valid frame into the time reel. If the frame
// is the next one in sequence, it advances the reel head forward and emits a // is the next one in sequence, it advances the reel head forward and emits a
// new frame on the new frame channel. // new frame on the new frame channel.
func (m *MasterTimeReel) Insert(frame *protobufs.ClockFrame) error { func (m *MasterTimeReel) Insert(
frame *protobufs.ClockFrame,
isSync bool,
) error {
go func() { go func() {
m.frames <- frame m.frames <- frame
}() }()

View File

@ -54,7 +54,7 @@ func TestMasterTimeReel(t *testing.T) {
frame, err = prover.ProveMasterClockFrame(frame, i+1, 10) frame, err = prover.ProveMasterClockFrame(frame, i+1, 10)
assert.NoError(t, err) assert.NoError(t, err)
err := m.Insert(frame) err := m.Insert(frame, false)
assert.NoError(t, err) assert.NoError(t, err)
} }
@ -69,7 +69,7 @@ func TestMasterTimeReel(t *testing.T) {
} }
for i := 99; i >= 0; i-- { for i := 99; i >= 0; i-- {
err := m.Insert(insertFrames[i]) err := m.Insert(insertFrames[i], false)
assert.NoError(t, err) assert.NoError(t, err)
} }

View File

@ -7,7 +7,7 @@ import (
type TimeReel interface { type TimeReel interface {
Start() error Start() error
Stop() Stop()
Insert(frame *protobufs.ClockFrame) error Insert(frame *protobufs.ClockFrame, isSync bool) error
Head() (*protobufs.ClockFrame, error) Head() (*protobufs.ClockFrame, error)
NewFrameCh() <-chan *protobufs.ClockFrame NewFrameCh() <-chan *protobufs.ClockFrame
BadFrameCh() <-chan *protobufs.ClockFrame BadFrameCh() <-chan *protobufs.ClockFrame