Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Implemented BIOS Boot node exclusion, by publishing a launch_block of 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
abourget committed May 29, 2018
1 parent c0e9d9e commit 5a10484
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bios/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ func (b *BIOS) shuffleProducers() {
b.Log.Println("Shuffling producers listed in the launch file")
r := rand.New(b.RandSource)
// shuffle top 25%, capped to 5
shuffleHowMany := int64(math.Min(math.Ceil(float64(len(b.ShuffledProducers))*0.25), 5))
shuffleHowMany := int64(math.Min(math.Ceil(float64(len(b.ShuffledProducers))*0.25), RandomBootFromTop))
if shuffleHowMany > 1 {
b.Log.Println("- Shuffling top", shuffleHowMany)
for round := 0; round < 100; round++ {
Expand Down
35 changes: 29 additions & 6 deletions bios/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"gonum.org/v1/gonum/graph/topo"
)

const ContentConsensusRequiredFromTop = 7
const ContentConsensusRequiredFromTop = 8
const RandomBootFromTop = 5

type Network struct {
Log *Logger
Expand Down Expand Up @@ -383,12 +384,32 @@ func (net *Network) OrderedPeers(network *simple.WeightedDirectedGraph) (out []*
if out[i].TotalWeight == out[j].TotalWeight {
return out[i].AccountName() < out[j].AccountName()
}

return out[i].TotalWeight > out[j].TotalWeight
})

out = bootOptInFilter(out)

return
}

func bootOptInFilter(in []*Peer) (out []*Peer) {
var launchers []*Peer
var nonLaunchers []*Peer
for _, el := range in {
if el.Discovery.SeedNetworkLaunchBlock == 0 {
nonLaunchers = append(nonLaunchers, el)
} else {
launchers = append(launchers, el)
}
}
maxLaunchers := RandomBootFromTop
if len(launchers) < RandomBootFromTop {
maxLaunchers = len(launchers)
}
return append(launchers[:maxLaunchers], append(nonLaunchers, launchers[maxLaunchers:]...)...)
}

func (net *Network) GetBlockHeight(height uint32) (eos.SHA256Bytes, error) {
resp, err := net.SeedNetAPI.GetBlockByNum(height)
if err != nil {
Expand Down Expand Up @@ -521,12 +542,14 @@ func (net *Network) PrintOrderedPeers(orderedPeers []*Peer) {
"Role | Seed Account | Target Acct | Weight | GMT | Launch Block | Contents",
"---- | ------------ | ----------- | ------ | --- | ------------ | --------",
}
columns = append(columns, fmt.Sprintf("BIOS NODE | %s | %s", orderedPeers[0].Columns(), peerContent[0]))
for i := 1; i < 22 && len(orderedPeers) > i; i++ {
columns = append(columns, fmt.Sprintf("ABP %02d | %s | %s", i, orderedPeers[i].Columns(), peerContent[i]))
for i := 0; i < RandomBootFromTop && len(orderedPeers) > i; i++ {
columns = append(columns, fmt.Sprintf("BOOT CAND. | %s | %s", orderedPeers[i].Columns(), peerContent[i]))
}
for i := RandomBootFromTop; i < 21 && len(orderedPeers) > i; i++ {
columns = append(columns, fmt.Sprintf("ABP %02d | %s | %s", i+1, orderedPeers[i].Columns(), peerContent[i]))
}
for i := 22; len(orderedPeers) > i; i++ {
columns = append(columns, fmt.Sprintf("Part. %02d | %s | %s", i, orderedPeers[i].Columns(), peerContent[i]))
for i := 21; len(orderedPeers) > i; i++ {
columns = append(columns, fmt.Sprintf("Part. %02d | %s | %s", i+1, orderedPeers[i].Columns(), peerContent[i]))
}
net.Log.Println(columnize.SimpleFormat(columns))

Expand Down
48 changes: 48 additions & 0 deletions bios/network_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package bios

import (
"testing"

"github.com/eoscanada/eos-bios/bios/disco"
"github.com/stretchr/testify/assert"
)

func TestBootOptInFilter(t *testing.T) {
tests := []struct {
in string
out string
}{
{"ABcDeFGhIJ", "ABDFGcehIJ"},
{"ABCDEFGHIJ", "ABCDEFGHIJ"},
{"abcdeFGHIJ", "FGHIJabcde"},
{"abcdefGHIJ", "GHIJabcdef"},
{"abcdefGHIJKLM", "GHIJKabcdefLM"},
{"abcdefghIJ", "IJabcdefgh"},
{"abcde", "abcde"},
{"abC", "Cab"},
{"abcdeF", "Fabcde"},
{"abcdeFGHI", "FGHIabcde"},
}

for _, test := range tests {
in := bootFilterPeers(test.in)
out := bootFilterPeers(test.out)

assert.Equal(t, out, bootOptInFilter(in))
}
}

func bootFilterPeers(in string) []*Peer {
var out []*Peer
for _, c := range in {
block := 0
if c < 92 {
block = 1
}
out = append(out, &Peer{Discovery: &disco.Discovery{
SeedNetworkAccountName: AN(string(c)),
SeedNetworkLaunchBlock: uint64(block),
}})
}
return out
}
13 changes: 10 additions & 3 deletions bios/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,18 @@ func (p *Peer) String() string {
}

func (p *Peer) Columns() string {
active := ""
add := ""
if p.Active() {
active = "A "
add += "A"
if p.Discovery.SeedNetworkLaunchBlock != 0 {
add += "B"
}
}
return fmt.Sprintf("%s | %s | %s%d | %d | %d", p.Discovery.SeedNetworkAccountName, p.Discovery.TargetAccountName, active, p.TotalWeight, p.Discovery.GMTOffset, p.Discovery.SeedNetworkLaunchBlock)
if len(add) != 0 {
add += " "
}

return fmt.Sprintf("%s | %s | %s%d | %d | %d", p.Discovery.SeedNetworkAccountName, p.Discovery.TargetAccountName, add, p.TotalWeight, p.Discovery.GMTOffset, p.Discovery.SeedNetworkLaunchBlock)
}

// PeerEdge is an internal structure that links two Discovery peers.
Expand Down
5 changes: 4 additions & 1 deletion sample_config/my_discovery_file.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ seed_network_peers:
comment: "Insert why you think they're worth that weight"
weight: 20

seed_network_launch_block: 551 # Block on the SEED EOS network before we orchestrate the TARGET network launch. Putting a past block will start orchestration right away.
# Block on the SEED EOS network before we orchestrate the TARGET network launch.
# Putting a past block will start orchestration right away.
# Setting it 0 means you OPT OUT of being selected the BIOS Boot node.
seed_network_launch_block: 0

urls:
- https://website.com
Expand Down

0 comments on commit 5a10484

Please sign in to comment.