Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
StronglySee --> ForklessSee
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxdxdev committed Sep 11, 2019
1 parent 2cbebc8 commit de8ba48
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/poset/checkpoint.go
Expand Up @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions src/poset/election/election.go
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/poset/election/election_math.go
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/poset/election/election_test.go
Expand Up @@ -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{
Expand All @@ -263,7 +263,7 @@ func testProcessRoot(
}
ordered = unordered.ByParents()

election := New(mm, 0, stronglySeeFn)
election := New(mm, 0, forklessSeeFn)

// processing:
var alreadyDecided bool
Expand Down
8 changes: 4 additions & 4 deletions src/poset/epoch.go
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/poset/poset.go
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/vector/strongly_see.go → src/vector/forkless_see.go
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
26 changes: 13 additions & 13 deletions src/vector/strongly_see_test.go → src/vector/forkless_see_test.go
Expand Up @@ -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 ║
Expand All @@ -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 ║
Expand All @@ -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) ║
Expand All @@ -61,10 +61,10 @@ a1_5 ────╣ ║

}

// testStronglySeen uses event name agreement:
// testForklessSeen uses event name agreement:
// "<name>_<level>[(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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
║ ║
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
}
}
Expand Down

0 comments on commit de8ba48

Please sign in to comment.