Skip to content

Commit

Permalink
cleanup epoch tests (#19)
Browse files Browse the repository at this point in the history
* cleanup

* remove println

* add lock

* revert
  • Loading branch information
samliok authored and yacovm committed Dec 24, 2024
1 parent 8f7877f commit 07ab3d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
5 changes: 2 additions & 3 deletions epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,16 +1039,15 @@ func (e *Epoch) storeProposal(block Block) bool {

// Have we already received a block from that node?
// If so, it cannot change its mind and send us a different block.
round, exists := e.rounds[md.Round]
if exists {
if _, exists := e.rounds[md.Round]; exists {
// We have already received a block for this round in the past, refuse receiving an alternative block.
// We do this because we may have already voted for a different block.
// Refuse processing the block to not be coerced into voting for a different block.
e.Logger.Warn("Already received block for round", zap.Uint64("round", md.Round))
return false
}

round = NewRound(block)
round := NewRound(block)
e.rounds[md.Round] = round
// We might have received votes and finalizations from future rounds before we received this block.
// So load the messages into our round data structure now that we have created it.
Expand Down
32 changes: 15 additions & 17 deletions epoch_multinode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ package simplex_test
import (
"bytes"
"context"
"github.com/stretchr/testify/require"
. "simplex"
"simplex/wal"
"testing"

"github.com/stretchr/testify/require"
)

func TestSimplexMultiNodeSimple(t *testing.T) {
Expand All @@ -29,14 +30,19 @@ func TestSimplexMultiNodeSimple(t *testing.T) {
n.start()
}

for seq := 0; seq < 1; seq++ {
for seq := 0; seq < 10; seq++ {
for _, n := range instances {
n.ledger.waitForBlockCommit(uint64(seq))
bb.triggerNewBlock()
}
bb.triggerNewBlock()
}
}

func (t *testInstance) start() {
require.NoError(t.t, t.e.Start())
go t.handleMessages()
}

func newSimplexNode(t *testing.T, id uint8, net *inMemNetwork, bb BlockBuilder) *testInstance {
l := makeLogger(t, int(id))
storage := newInMemStorage()
Expand Down Expand Up @@ -84,20 +90,12 @@ type testInstance struct {
t *testing.T
}

func (t *testInstance) start() {
require.NoError(t.t, t.e.Start())
go t.run()
}

func (t *testInstance) run() {
for {
select {
case msg := <-t.ingress:
err := t.e.HandleMessage(msg.msg, msg.from)
require.NoError(t.t, err)
if err != nil {
return
}
func (t *testInstance) handleMessages() {
for msg := range t.ingress {
err := t.e.HandleMessage(msg.msg, msg.from)
require.NoError(t.t, err)
if err != nil {
return
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions epoch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ func (mem *InMemStorage) Retrieve(seq uint64) (Block, FinalizationCertificate, b
}

func (mem *InMemStorage) Index(seq uint64, block Block, certificate FinalizationCertificate) {
mem.lock.Lock()
defer mem.lock.Unlock()

_, ok := mem.data[seq]
if ok {
panic(fmt.Sprintf("block with seq %d already indexed!", seq))
Expand Down

0 comments on commit 07ab3d2

Please sign in to comment.