Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sambarnes committed Oct 29, 2018
1 parent 8ba1187 commit 1b44feb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
8 changes: 5 additions & 3 deletions state/dbStateManager.go
Expand Up @@ -1142,7 +1142,7 @@ func (list *DBStateList) ProcessBlocks(d *DBState) (progress bool) {
list.State.Balancehash = fs.GetBalanceHash(false)
list.State.LogPrintf("dbstateprocess", "dbht %d BalanceHash P %x T %x", dbht, list.State.Balancehash.Bytes()[0:4], tbh.Bytes()[0:4])
// Saving our state so we can reset it if we need to.
d.TmpSaveStruct = SaveFactomdState(list.State, d)
d.SaveStruct = SaveFactomdState(list.State, d)
return
}

Expand Down Expand Up @@ -1482,9 +1482,11 @@ func (list *DBStateList) SaveDBStateToDB(d *DBState) (progress bool) {
// We will only save blocks marked to be saved. As such, this must follow
// the "d.saved = true" above
if list.State.StateSaverStruct.FastBoot {
d.SaveStruct = d.TmpSaveStruct
//d.SaveStruct = d.TmpSaveStruct
err := list.State.StateSaverStruct.SaveDBStateList(list.State.DBStates, list.State.Network)
list.State.LogPrintf("dbstatesprocess", "Error while saving Fastboot %v", err)
if err != nil {
list.State.LogPrintf("dbstatesprocess", "Error while saving Fastboot %v", err)
}
}
// Now that we have saved the perm balances, we can clear the api hashmaps that held the differences
// between the actual saved block prior, and this saved block. If you are looking for balances of
Expand Down
12 changes: 5 additions & 7 deletions state/stateConsensus.go
Expand Up @@ -939,14 +939,12 @@ func (s *State) FollowerExecuteDBState(msg interfaces.IMsg) {
}
s.DBStates.TimeToAsk = nil

if dbstatemsg.IsLocal() {
if s.StateSaverStruct.FastBoot {
dbstate.SaveStruct = SaveFactomdState(s, dbstate)
if dbstatemsg.IsLocal() && s.StateSaverStruct.FastBoot {
dbstate.SaveStruct = SaveFactomdState(s, dbstate)

err := s.StateSaverStruct.SaveDBStateList(s.DBStates, s.Network)
if err != nil {
panic(err)
}
err := s.StateSaverStruct.SaveDBStateList(s.DBStates, s.Network)
if err != nil {
panic(err)
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions state/stateSaver.go
Expand Up @@ -38,7 +38,7 @@ func (sss *StateSaverStruct) SaveDBStateList(ss *DBStateList, networkName string
hsb := int(ss.GetHighestSavedBlk())
//Save only every FastSaveRate states

if hsb%ss.State.FastSaveRate != 0 || hsb < ss.State.FastSaveRate {
if hsb%ss.State.FastSaveRate != 0 || hsb < ss.State.FastSaveRate || ss.State.DBFinished == true {
return nil
}

Expand All @@ -60,19 +60,14 @@ func (sss *StateSaverStruct) SaveDBStateList(ss *DBStateList, networkName string
fmt.Fprintln(os.Stderr, "SaveState MarshalBinary Failed", err)
return err
}

//adding an integrity check
h := primitives.Sha(b)
b = append(h.Bytes(), b...)
sss.TmpState = b
sss.TmpDBHt = ss.State.LLeaderHeight

{ /// Debug code, check if I can unmarshal the object myself.
test := new(DBStateList)
test.UnmarshalBinary(b)
if err != nil {
fmt.Fprintln(os.Stderr, "SaveState UnmarshalBinary Failed", err)
}

h := primitives.NewZeroHash()
b, err = h.UnmarshalBinaryData(b)
if err != nil {
Expand All @@ -83,6 +78,13 @@ func (sss *StateSaverStruct) SaveDBStateList(ss *DBStateList, networkName string
fmt.Fprintln(os.Stderr, "LoadDBStateList - Integrity hashes do not match!")
return nil
}

test := new(DBStateList)
test.State = ss.State
err = test.UnmarshalBinary(b)
if err != nil {
fmt.Fprintln(os.Stderr, "SaveState UnmarshalBinary Failed", err)
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion wsapi/wsapi.go
Expand Up @@ -55,7 +55,7 @@ func Start(state interfaces.IState) {
server = web.NewServer()

server.Logger.SetOutput(ioutil.Discard)
server.Config.CorsDomains = state.GetCorsDomains()
//server.Config.CorsDomains = state.GetCorsDomains()

Servers[state.GetPort()] = server
server.Env["state"] = state
Expand Down

0 comments on commit 1b44feb

Please sign in to comment.