From de8ba483155c1fd30e266243c31b9e85cf895602 Mon Sep 17 00:00:00 2001 From: sfxdxdev Date: Wed, 11 Sep 2019 20:48:26 +1000 Subject: [PATCH] StronglySee --> ForklessSee --- src/poset/checkpoint.go | 2 +- src/poset/election/election.go | 14 +++++----- src/poset/election/election_math.go | 4 +-- src/poset/election/election_test.go | 4 +-- src/poset/epoch.go | 8 +++--- src/poset/poset.go | 2 +- .../{strongly_see.go => forkless_see.go} | 4 +-- ...ongly_see_test.go => forkless_see_test.go} | 26 +++++++++---------- 8 files changed, 32 insertions(+), 32 deletions(-) rename src/vector/{strongly_see.go => forkless_see.go} (91%) rename src/vector/{strongly_see_test.go => forkless_see_test.go} (99%) diff --git a/src/poset/checkpoint.go b/src/poset/checkpoint.go index 1ecf40315..7768abab0 100644 --- a/src/poset/checkpoint.go +++ b/src/poset/checkpoint.go @@ -48,7 +48,7 @@ func (p *Poset) Bootstrap(applyBlock inter.ApplyBlockFn) { // restore current epoch p.loadEpoch() p.seeVec = vector.NewIndex(p.Members, p.store.epochTable.VectorIndex) - p.election = election.New(p.Members, p.LastDecidedFrame+1, p.rootStronglySeeRoot) + p.election = election.New(p.Members, p.LastDecidedFrame+1, p.rootForklessSeeRoot) // events reprocessing p.handleElection(nil) diff --git a/src/poset/election/election.go b/src/poset/election/election.go index 64b1f04b4..78840946b 100644 --- a/src/poset/election/election.go +++ b/src/poset/election/election.go @@ -26,15 +26,15 @@ type ( votes map[voteId]voteValue // external world - stronglySee RootStronglySeeRootFn + forklessSee RootForklessSeeRootFn logger.Instance } - // RootStronglySeeRootFn returns hash of root B, if root A strongly sees root B. + // RootForklessSeeRootFn returns hash of root B, if root A strongly sees root B. // Due to a fork, there may be many roots B with the same slot, // but strongly seen may be only one of them (if no more than 1/3n are Byzantine), with a specific hash. - RootStronglySeeRootFn func(a hash.Event, b common.Address, f idx.Frame) *hash.Event + RootForklessSeeRootFn func(a hash.Event, b common.Address, f idx.Frame) *hash.Event // Slot specifies a root slot {addr, frame}. Normal members can have only one root with this pair. // Due to a fork, different roots may occupy the same slot @@ -68,10 +68,10 @@ type ElectionRes struct { func New( members pos.Members, frameToDecide idx.Frame, - stronglySeeFn RootStronglySeeRootFn, + forklessSeeFn RootForklessSeeRootFn, ) *Election { el := &Election{ - stronglySee: stronglySeeFn, + forklessSee: forklessSeeFn, Instance: logger.MakeInstance(), } @@ -105,14 +105,14 @@ func (el *Election) notDecidedRoots() []common.Address { } // @return all the roots which are strongly seen by the specified root at the specified frame -func (el *Election) stronglySeenRoots(root hash.Event, frame idx.Frame) []RootAndSlot { +func (el *Election) forklessSeenRoots(root hash.Event, frame idx.Frame) []RootAndSlot { seenRoots := make([]RootAndSlot, 0, len(el.members)) for member := range el.members { slot := Slot{ Frame: frame, Addr: member, } - seenRoot := el.stronglySee(root, member, frame) + seenRoot := el.forklessSee(root, member, frame) if seenRoot != nil { seenRoots = append(seenRoots, RootAndSlot{ Root: *seenRoot, diff --git a/src/poset/election/election_math.go b/src/poset/election/election_math.go index 268110aba..66190ba10 100644 --- a/src/poset/election/election_math.go +++ b/src/poset/election/election_math.go @@ -26,14 +26,14 @@ func (el *Election) ProcessRoot(newRoot RootAndSlot) (*ElectionRes, error) { if round == 1 { // in initial round, vote "yes" if subject is strongly seen - seenRoot := el.stronglySee(newRoot.Root, memberSubject, el.frameToDecide) + seenRoot := el.forklessSee(newRoot.Root, memberSubject, el.frameToDecide) vote.yes = seenRoot != nil vote.decided = false if seenRoot != nil { vote.seenRoot = *seenRoot } } else if round > 1 { - sSeenRoots := el.stronglySeenRoots(newRoot.Root, newRoot.Slot.Frame-1) + sSeenRoots := el.forklessSeenRoots(newRoot.Root, newRoot.Slot.Frame-1) var ( yesVotes = el.members.NewCounter() diff --git a/src/poset/election/election_test.go b/src/poset/election/election_test.go index 2cb991000..3e4b0fee4 100644 --- a/src/poset/election/election_test.go +++ b/src/poset/election/election_test.go @@ -240,7 +240,7 @@ func testProcessRoot( } // strongly see fn: - stronglySeeFn := func(a hash.Event, b common.Address, f idx.Frame) *hash.Event { + forklessSeeFn := func(a hash.Event, b common.Address, f idx.Frame) *hash.Event { edge := fakeEdge{ from: a, to: Slot{ @@ -263,7 +263,7 @@ func testProcessRoot( } ordered = unordered.ByParents() - election := New(mm, 0, stronglySeeFn) + election := New(mm, 0, forklessSeeFn) // processing: var alreadyDecided bool diff --git a/src/poset/epoch.go b/src/poset/epoch.go index bb2d78df3..432dd08e0 100644 --- a/src/poset/epoch.go +++ b/src/poset/epoch.go @@ -15,7 +15,7 @@ import ( ) const ( - // EpochLen is a count of FW per epoch. + // EpochLen is a count of frames per epoch. EpochLen idx.Frame = 100 firstFrame = idx.Frame(1) @@ -91,10 +91,10 @@ func (p *Poset) GetMembers() pos.Members { return p.Members.Copy() } -// rootStronglySeeRoot returns hash of root B, if root A strongly sees root B. +// rootForklessSeeRoot returns hash of root B, if root A strongly sees root B. // Due to a fork, there may be many roots B with the same slot, // but strongly seen may be only one of them (if no more than 1/3n are Byzantine), with a specific hash. -func (p *Poset) rootStronglySeeRoot(a hash.Event, bNode common.Address, bFrame idx.Frame) *hash.Event { +func (p *Poset) rootForklessSeeRoot(a hash.Event, bNode common.Address, bFrame idx.Frame) *hash.Event { var bHash *hash.Event p.store.ForEachRootFrom(bFrame, bNode, func(f idx.Frame, from common.Address, b hash.Event) bool { if f != bFrame { @@ -103,7 +103,7 @@ func (p *Poset) rootStronglySeeRoot(a hash.Event, bNode common.Address, bFrame i if from != bNode { p.Log.Crit("node mismatch") } - if p.seeVec.StronglySee(a, b) { + if p.seeVec.ForklessSee(a, b) { bHash = &b return false } diff --git a/src/poset/poset.go b/src/poset/poset.go index 48a2307e2..3953760be 100644 --- a/src/poset/poset.go +++ b/src/poset/poset.go @@ -255,7 +255,7 @@ func (p *Poset) calcFrameIdx(e *inter.Event, checkOnly bool) (frame idx.Frame, i if !checkOnly || e.IsRoot { // check s.seeing of prev roots only if called by creator, or if creator has marked that event is root p.store.ForEachRoot(maxParentsFrame, func(f idx.Frame, from common.Address, root hash.Event) bool { - if p.seeVec.StronglySee(e.Hash(), root) { + if p.seeVec.ForklessSee(e.Hash(), root) { sSeenCounter.Count(from) } return !sSeenCounter.HasQuorum() diff --git a/src/vector/strongly_see.go b/src/vector/forkless_see.go similarity index 91% rename from src/vector/strongly_see.go rename to src/vector/forkless_see.go index 7be6a5190..30fc95a79 100644 --- a/src/vector/strongly_see.go +++ b/src/vector/forkless_see.go @@ -4,7 +4,7 @@ import ( "github.com/Fantom-foundation/go-lachesis/src/hash" ) -// StronglySee calculates "sufficient coherence" between the events. +// ForklessSee calculates "sufficient coherence" between the events. // The A.HighestBefore array remembers the sequence number of the last // event by each member that is an ancestor of A. The array for // B.LowestAfter remembers the sequence number of the earliest @@ -13,7 +13,7 @@ import ( // than or equal to the corresponding element of the B.LowestAfter // array. If there are more than 2n/3 such matches, then the A and B // have achieved sufficient coherency. -func (vi *Index) StronglySee(aID, bID hash.Event) bool { +func (vi *Index) ForklessSee(aID, bID hash.Event) bool { // get events by hash a := vi.GetEvent(aID) if a == nil { diff --git a/src/vector/strongly_see_test.go b/src/vector/forkless_see_test.go similarity index 99% rename from src/vector/strongly_see_test.go rename to src/vector/forkless_see_test.go index 349a949c8..8362d8596 100644 --- a/src/vector/strongly_see_test.go +++ b/src/vector/forkless_see_test.go @@ -18,10 +18,10 @@ import ( "github.com/Fantom-foundation/go-lachesis/src/logger" ) -func TestStronglySeenClassic(t *testing.T) { +func TestForklessSeenClassic(t *testing.T) { t.Run("step 3", func(t *testing.T) { - testStronglySeen(t, ` + testForklessSeen(t, ` a0_1(3) b0_1 c0_1 ║ ║ ║ ╠─────── b1_2 ║ @@ -32,7 +32,7 @@ a0_1(3) b0_1 c0_1 }) t.Run("step 4", func(t *testing.T) { - testStronglySeen(t, ` + testForklessSeen(t, ` a0_1(3) b0_1 c0_1 ║ ║ ║ ╠─────── b1_2 ║ @@ -45,7 +45,7 @@ a0_1(3) b0_1 c0_1 }) t.Run("step 5", func(t *testing.T) { - testStronglySeen(t, ` + testForklessSeen(t, ` a0_1(3) b0_1(5) c0_1(5) ║ ║ ║ ╠─────── b1_2(5) ║ @@ -61,10 +61,10 @@ a1_5 ────╣ ║ } -// testStronglySeen uses event name agreement: +// testForklessSeen uses event name agreement: // "_[(by-level)]", // where by-level means that event is strongly seen by all event with level >= by-level. -func testStronglySeen(t *testing.T, dag string) { +func testForklessSeen(t *testing.T, dag string) { logger.SetTestMode(t) assertar := assert.New(t) @@ -93,7 +93,7 @@ func testStronglySeen(t *testing.T, dag string) { whom := ev.Hash() if !assertar.Equal( bylevel > 0 && bylevel <= level, - vi.StronglySee(who, whom), + vi.ForklessSee(who, whom), fmt.Sprintf("%s strongly sees %s", who.String(), whom.String()), ) { return @@ -125,10 +125,10 @@ func decode(dsc string) (level, bylevel int64) { return } -func TestStronglySeenRandom(t *testing.T) { +func TestForklessSeenRandom(t *testing.T) { assertar := assert.New(t) - // generated by codegen4StronglySeenStability() + // generated by codegen4ForklessSeenStability() dag := ` a000 ║ ║ @@ -399,7 +399,7 @@ func TestStronglySeenRandom(t *testing.T) { _, expect := relations[e1name][e2name] if !assertar.Equal( expect, - vi.StronglySee(e1.Hash(), e2.Hash()), + vi.ForklessSee(e1.Hash(), e2.Hash()), fmt.Sprintf("%s strongly sees %s", e1.Hash(), e2.Hash()), ) { return @@ -605,8 +605,8 @@ func TestRandomForks(t *testing.T) { } /* -// codegen4StronglySeenStability is for test data generation. -func codegen4StronglySeenStability() { +// codegen4ForklessSeenStability is for test data generation. +func codegen4ForklessSeenStability() { peers := inter.GenNodes(4) events := inter.GenEventsByNode(peers, 20, 2, nil, nil, nil) @@ -653,7 +653,7 @@ func codegen4StronglySeenStability() { for _, e1 := range dag { sees := fmt.Sprintf("\"%s\": map[string]struct{}{", e1.Hash()) for _, e2 := range dag { - if vi.StronglySee(e1.Hash(), e2.Hash()) { + if vi.ForklessSee(e1.Hash(), e2.Hash()) { sees = sees + fmt.Sprintf("\"%s\":{},", e2.Hash()) } }