Skip to content

Commit

Permalink
fix identity reload timing
Browse files Browse the repository at this point in the history
  • Loading branch information
stackdump committed Feb 14, 2019
1 parent c22ec34 commit 59010f9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
14 changes: 7 additions & 7 deletions simTest/BrainSwap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestBrainSwap(t *testing.T) {

// FIXME update to match test data
params := map[string]string{
"--db": "LDB", // NOTE: using LEVELDB
"--db": "LDB", // NOTE: using MAP causes an occasional error see FD-825
"--network": "LOCAL",
"--net": "alot+",
"--enablenet": "true",
Expand All @@ -46,12 +46,12 @@ func TestBrainSwap(t *testing.T) {
"--checkheads": "false",
"--controlpanelsetting": "readwrite",
//"--debuglog": ".",
"--logPort": "38000",
"--port": "38001",
"--controlpanelport": "38002",
"--networkport": "38003",
"--peers": peers,
"--factomhome": factomHome,
"--logPort": "38000",
"--port": "38001",
"--controlpanelport": "38002",
"--networkport": "38003",
"--peers": peers,
"--factomhome": factomHome,
}

state0 := SetupSim(givenNodes, params, int(maxBlocks), 0, 0, t)
Expand Down
8 changes: 5 additions & 3 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,15 @@ func (s *State) IncECommits() {
s.ECommits++
}

func (s *State) GetAckChange() error {
func (s *State) GetAckChange() (bool, error) {
var flag bool
change, err := util.GetChangeAcksHeight(s.ConfigFilePath)
if err != nil {
return err
return flag, err
}
flag = s.AckChange != change
s.AckChange = change
return nil
return flag, nil
}

func (s *State) LoadConfig(filename string, networkFlag string) {
Expand Down
23 changes: 17 additions & 6 deletions state/stateConsensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ func (s *State) ReviewHolding() {
}

func (s *State) MoveStateToHeight(dbheight uint32, newMinute int) {

if newMinute == 0 {
s.CheckForIDChange(dbheight)
}

s.LogPrintf("dbstateprocess", "MoveStateToHeight(%d-:-%d) called from %s", dbheight, newMinute, atomic.WhereAmIString(1))
if (s.LLeaderHeight+1 == dbheight && newMinute == 0) || (s.LLeaderHeight == dbheight && s.CurrentMinute+1 == newMinute) {
// these are the allowed cases; move to nextblock-:-0 or move to next minute
Expand Down Expand Up @@ -1844,6 +1849,7 @@ func (s *State) ProcessEOM(dbheight uint32, msg interfaces.IMsg) bool {
s.LogPrintf("dbsig-eom", "Follower jump to minute %d from %d", s.CurrentMinute, int(e.Minute))
}
s.MoveStateToHeight(e.DBHeight, int(e.Minute+1))

} else {
s.MoveStateToHeight(s.LLeaderHeight, s.CurrentMinute+1)
}
Expand Down Expand Up @@ -1909,9 +1915,6 @@ func (s *State) ProcessEOM(dbheight uint32, msg interfaces.IMsg) bool {
s.DBStates.FixupLinks(prev, dbstate)
}

s.GetAckChange()
s.CheckForIDChange()

s.DBSigProcessed = 0
s.TempBalanceHash = s.FactoidState.GetBalanceHash(true)

Expand Down Expand Up @@ -2036,13 +2039,20 @@ func (s *State) GetUnsyncedServersString(dbheight uint32) string {
return ids
}

func (s *State) CheckForIDChange() {
func (s *State) CheckForIDChange(targetHeight uint32) {
changed, _ := s.GetAckChange()
var reloadIdentity bool = false
if s.AckChange > 0 {
if s.LLeaderHeight >= s.AckChange {

if changed {
s.LogPrintf("AckChange", "AckChange %v", s.AckChange)
}

if s.AckChange > 0 { // NOTE: setting to 0 or negative disables identity reloading
if targetHeight >= s.AckChange {
reloadIdentity = true
}
}

if reloadIdentity {
config := util.ReadConfig(s.ConfigFilePath)
var err error
Expand All @@ -2052,6 +2062,7 @@ func (s *State) CheckForIDChange() {
}
s.LocalServerPrivKey = config.App.LocalServerPrivKey
s.initServerKeys()
s.LogPrintf("AckChange", "reloadIdentity local_priv: %v pub: %v, priv: %v", s.LocalServerPrivKey, s.GetServerPublicKey(), s.GetServerPrivateKey())
}
}

Expand Down

0 comments on commit 59010f9

Please sign in to comment.