Skip to content

Commit

Permalink
Merge pull request #538 from FactomProject/FD-628_DBSig_extra_election
Browse files Browse the repository at this point in the history
Fix handling of extra DBSig messages
  • Loading branch information
PaulSnow committed Aug 24, 2018
2 parents 06cd884 + c98b46c commit 56ff91e
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 1 deletion.
120 changes: 120 additions & 0 deletions engine/factomd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/FactomProject/factomd/activations"
"github.com/FactomProject/factomd/common/globals"
"github.com/FactomProject/factomd/common/primitives"
"github.com/FactomProject/factomd/common/primitives/random"
. "github.com/FactomProject/factomd/engine"
"github.com/FactomProject/factomd/state"
"github.com/FactomProject/factomd/wsapi"
Expand Down Expand Up @@ -1191,3 +1192,122 @@ func CheckAuthoritySet(leaders int, audits int, t *testing.T) {
t.Fail()
}
}

func TestDBsigElectionEvery2Block(t *testing.T) {
if ranSimTest {
return
}

ranSimTest = true

iterations := 1
state0 := SetupSim("LLLLLLAF", "LOCAL", map[string]string{"--debuglog": "fault|badmsg|network|process|dbsig", "--faulttimeout": "10"}, t)

StatusEveryMinute(state0)
runCmd("S10") // Set Drop Rate to 1.0 on everyone

CheckAuthoritySet(6, 1, t)

for j := 0; j <= iterations; j++ {
// for leader 1 thu 7 kill each in turn
for i := 1; i < 7; i++ {
s := GetFnodes()[i].State
if !s.IsLeader() {
panic("Can't kill a audit and cause an election")
}
WaitForMinute(s, 9) // wait till the victim is at minute 9
// wait till minute flips
for s.CurrentMinute != 0 {
runtime.Gosched()
}
s.SetNetStateOff(true) // kill the victim
s.LogPrintf("faulting", "Stopped %s\n", s.FactomNodeName)
WaitForMinute(state0, 1) // Wait till FNode0 move ahead a minute (the election is over)
s.LogPrintf("faulting", "Start %s\n", s.FactomNodeName)
s.SetNetStateOff(false) // resurrect the victim

WaitBlocks(state0, 2) // wait till the victim is back as the audit server
WaitForMinute(state0, 8) // Wait till ablock is loaded

CheckAuthoritySet(6, 1, t) // check the authority set is as expected
}
}
t.Log("Shutting down the network")
for _, fn := range GetFnodes() {
fn.State.ShutdownChan <- 1
}

}

func TestDBSigElection(t *testing.T) {
if ranSimTest {
return
}
ranSimTest = true

state0 := SetupSim("LLLAF", "LOCAL", map[string]string{"--debuglog": "fault|badmsg|network|process|dbsig", "--faulttimeout": "10"}, t)
StatusEveryMinute(state0)

CheckAuthoritySet(3, 1, t)

s := GetFnodes()[2].State
if !s.IsLeader() {
panic("Can't kill a audit and cause an election")
}
WaitForMinute(s, 9) // wait till the victim is at minute 9
// wait till minute flips
for s.CurrentMinute != 0 {
runtime.Gosched()
}
s.SetNetStateOff(true) // kill the victim
s.LogPrintf("faulting", "Stopped %s\n", s.FactomNodeName)
WaitForMinute(state0, 1) // Wait till FNode0 move ahead a minute (the election is over)
s.LogPrintf("faulting", "Start %s\n", s.FactomNodeName)
s.SetNetStateOff(false) // resurrect the victim

WaitBlocks(state0, 2) // wait till the victim is back as the audit server
WaitForMinute(state0, 1) // Wait till ablock is loaded
WaitForMinute(state0, 2) // Wait another couple minute in case any nodes are behind

CheckAuthoritySet(3, 1, t) // check the authority set is as expected

t.Log("Shutting down the network")
for _, fn := range GetFnodes() {
fn.State.ShutdownChan <- 1
}

}

// Cheap tests for developing binary search commits algorithm

func TestPass(t *testing.T) {
if ranSimTest {
return
}

ranSimTest = true

}

func TestFail(t *testing.T) {
if ranSimTest {
return
}

ranSimTest = true
t.Fatal("Failed")

}

func TestRandom(t *testing.T) {
if ranSimTest {
return
}

ranSimTest = true

if random.RandUInt8() > 200 {
t.Fatal("Failed")
}

}
49 changes: 49 additions & 0 deletions engine/search.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#/bin/sh
#set -x

# git log v5.4.2 | head -n 1092 | grep -B5 " Merge " | grep -E "^commit" | awk ' {print $2;}' > x

test="$1"
shift
################################
# AWK scripts #
################################
read -d '' scriptVariable << 'EOF'
func mysystem(cmd) {
print cmd;
print "\n",cmd,"\n" ;
rc = system(cmd " 2>&1");
if(rc!=0) {
print "Exit", rc;
exit(rc);
}
return rc;
}
/^#/ {print "Skipping", $1; next;}
{branches[x++] = $0;}
END {
PROCINFO["@ind_num_asc"]
for(i in branches) {
branch = branches[i];
print "Testing Branch ", branch;
mysystem("git reset --hard");
mysystem("git checkout " branch);
mysystem("git checkout Rolling_DBSIG_Test_v5.2 factomd_test.go");
rc = system("go test --run " test);
print i, branch, "Exit Code", rc
}
}
EOF
################################
# End of AWK Scripts #
################################
rm -f runlog.txt
awk -v test=$test "$scriptVariable" $@ 2>&1 | tee -i runlog.txt | grep -E "Testing Branch|Exit Code"


15 changes: 14 additions & 1 deletion state/stateConsensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1222,8 +1222,21 @@ func (s *State) LeaderExecuteDBSig(m interfaces.IMsg) {
m.FollowerExecute(s)
return
}

if pl.VMs[dbs.VMIndex].Height > 0 {
s.LogMessage("executeMsg", "drop, slot 0 taken by", pl.VMs[dbs.VMIndex].List[0])
s.LogPrintf("executeMsg", "DBSig issue height = %d, length = %d", pl.VMs[dbs.VMIndex].Height, len(pl.VMs[dbs.VMIndex].List))
s.LogMessage("executeMsg", "drop, already processed ", pl.VMs[dbs.VMIndex].List[0])
return
}

if len(pl.VMs[dbs.VMIndex].List) > 0 && pl.VMs[dbs.VMIndex].List[0] != nil {
s.LogPrintf("executeMsg", "DBSig issue height = %d, length = %d", pl.VMs[dbs.VMIndex].Height, len(pl.VMs[dbs.VMIndex].List))
if pl.VMs[dbs.VMIndex].List[0] != m {
s.LogMessage("executeMsg", "drop, slot 0 taken by", pl.VMs[dbs.VMIndex].List[0])
} else {
s.LogMessage("executeMsg", "duplicate execute", pl.VMs[dbs.VMIndex].List[0])
}

return
}

Expand Down

0 comments on commit 56ff91e

Please sign in to comment.