Skip to content

Commit

Permalink
Fixed doubled entry bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePiachu committed Nov 6, 2015
1 parent 4797033 commit 6ae279b
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
8 changes: 4 additions & 4 deletions common/directoryBlock/directoryBlock.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func CreateDBlock(state interfaces.IState) (b interfaces.IDirectoryBlock, err er

b.SetHeader(new(DBlockHeader))
b.GetHeader().SetVersion(constants.VERSION_0)

if prev == nil {
b.GetHeader().SetPrevLedgerKeyMR(primitives.NewZeroHash())
b.GetHeader().SetPrevKeyMR(primitives.NewZeroHash())
Expand All @@ -225,15 +225,15 @@ func CreateDBlock(state interfaces.IState) (b interfaces.IDirectoryBlock, err er
}

adminblk := adminBlock.NewAdminBlock(state)
keymr,err := adminblk.GetKeyMR()
keymr, err := adminblk.GetKeyMR()
if err != nil {
panic(err.Error())
}
b.GetHeader().SetDBHeight(state.GetDBHeight())
b.SetDBEntries(make([]interfaces.IDBEntry, 0))
b.AddEntry(primitives.NewHash(constants.ADMIN_CHAINID), keymr)
b.AddEntry(primitives.NewHash(constants.EC_CHAINID), nil)
b.AddEntry(primitives.NewHash(constants.FACTOID_CHAINID), nil)
b.AddEntry(primitives.NewHash(constants.EC_CHAINID), primitives.NewZeroHash())
b.AddEntry(primitives.NewHash(constants.FACTOID_CHAINID), primitives.NewZeroHash())

return b, err
}
18 changes: 10 additions & 8 deletions common/messages/eom.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (m *EOM) Leader(state interfaces.IState) bool {

// Execute the leader functions of the given message
func (m *EOM) LeaderExecute(state interfaces.IState) error {
fmt.Println("Leader")
log.Println("Leader")
olddb := state.GetCurrentDirectoryBlock()
state.GetFactoidState().ProcessEndOfBlock(state)

Expand All @@ -141,9 +141,11 @@ func (m *EOM) LeaderExecute(state interfaces.IState) error {
panic(err.Error())
}
state.SetCurrentDirectoryBlock(db)
db.AddEntry(primitives.NewHash(constants.ADMIN_CHAINID), primitives.NewZeroHash()) // AdminBlock
db.AddEntry(primitives.NewHash(constants.EC_CHAINID), primitives.NewZeroHash()) // AdminBlock
db.AddEntry(primitives.NewHash(constants.FACTOID_CHAINID), primitives.NewZeroHash()) // AdminBlock
/*
db.AddEntry(primitives.NewHash(constants.ADMIN_CHAINID), primitives.NewZeroHash()) // AdminBlock
db.AddEntry(primitives.NewHash(constants.EC_CHAINID), primitives.NewZeroHash()) // EntryCredit Block
db.AddEntry(primitives.NewHash(constants.FACTOID_CHAINID), primitives.NewZeroHash()) // Factoid Block
*/

if olddb != nil {
bodyMR, err := olddb.BuildBodyMR()
Expand Down Expand Up @@ -183,15 +185,15 @@ func (m *EOM) FollowerExecute(state interfaces.IState) error {
case constants.NETWORK_LOCAL: // Local Network

default:
panic(fmt.Sprintf("Not implemented yet: Network Number %d",state.GetNetworkNumber()))
panic(fmt.Sprintf("Not implemented yet: Network Number %d", state.GetNetworkNumber()))
}

fmt.Println(state.GetServerState(), constants.SERVER_MODE)

if state.GetServerState() == constants.SERVER_MODE {
state.LeaderInMsgQueue() <- m
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"runtime"
"runtime/debug"
"strconv"
"strings"
)
Expand Down Expand Up @@ -36,6 +37,10 @@ func debugPrefix() string {
return file + ":" + strconv.Itoa(line) + " - "
}

func PrintStack() {
debug.PrintStack()
}

func Fatal(str string, args ...interface{}) {
printf(LogLevel == DebugLog, str+"\n", args...)
os.Exit(1)
Expand Down
1 change: 1 addition & 0 deletions timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func Timer(state interfaces.IState) {
// End of the last period, and this is a server, send messages that
// close off the minute.
if state.GetServerState() == 1 {
log.Println("NewEOM")
eom := messages.NewEOM(state, i)
state.InMsgQueue() <- eom
state.NetworkOutMsgQueue() <- eom
Expand Down
6 changes: 3 additions & 3 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ func Validator(state interfaces.IState) {

for {
msg := <-state.InMsgQueue() // Get message from the input queue

log.Println("Validator")
switch msg.Validate(state) { // Validate the message.
case 1: // Process if valid
// log.Printf("%20s %s\n", "Validator:", msg.String())
// log.Printf("%20s %s\n", "Validator:", msg.String())
if msg.Leader(state) {
state.LeaderInMsgQueue() <- msg
} else if msg.Follower(state) {
Expand All @@ -31,7 +31,7 @@ func Validator(state interfaces.IState) {
case -1: // Drop if invalid.
// Invalid. Just do nothing.
}
// fmt.Println(state)
// fmt.Println(state)
}

}

0 comments on commit 6ae279b

Please sign in to comment.