commitTime is used to derive next startTime. :)

This commit is contained in:
Jae Kwon
2014-09-08 15:32:08 -07:00
parent 5dfa2ecebb
commit 7523f501fd
4 changed files with 97 additions and 76 deletions
+9 -3
View File
@@ -52,15 +52,19 @@ func LoadState(db db_.Db) *State {
return s
}
func (s *State) Save() {
// Save this state into the db.
// For convenience, the commitTime (required by ConsensusManager)
// is saved here.
func (s *State) Save(commitTime time.Time) {
s.mtx.Lock()
defer s.mtx.Unlock()
s.commitTime = commitTime
s.accounts.Save()
var buf bytes.Buffer
var n int64
var err error
WriteUInt32(&buf, s.height, &n, &err)
WriteTime(&buf, s.commitTime, &n, &err)
WriteTime(&buf, commitTime, &n, &err)
WriteByteSlice(&buf, s.accounts.Hash(), &n, &err)
for _, validator := range s.validators.Map() {
WriteBinary(&buf, validator, &n, &err)
@@ -91,7 +95,9 @@ func (s *State) CommitTx(tx *Tx) error {
return nil
}
func (s *State) CommitBlock(b *Block, commitTime time.Time) error {
// This is called during staging.
// The resulting state is cached until it is actually committed.
func (s *State) CommitBlock(b *Block) error {
s.mtx.Lock()
defer s.mtx.Unlock()
// TODO commit the txs