Skip to content

Commit

Permalink
Fix PanicError construction and sim clock progress with historical me…
Browse files Browse the repository at this point in the history
…ssages. (#120)

Co-authored-by: Jakub Sztandera <[email protected]>
  • Loading branch information
anorth and Kubuxu authored Mar 14, 2024
1 parent f350090 commit 0e2629c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
14 changes: 5 additions & 9 deletions gpbft/participant.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,13 @@ type Participant struct {
}

type PanicError struct {
Err error
Err any
}

func (e *PanicError) Error() string {
return fmt.Sprintf("panic recovered: %v", e.Err)
}

func (e *PanicError) Unwrap() error {
return e.Err
}

func NewParticipant(id ActorID, config GraniteConfig, host Host) *Participant {
return &Participant{id: id, config: config, host: host}
}
Expand Down Expand Up @@ -67,7 +63,7 @@ func (p *Participant) CurrentRound() uint64 {
func (p *Participant) ReceiveECChain(chain ECChain) (err error) {
defer func() {
if r := recover(); r != nil {
err = &PanicError{Err: err}
err = &PanicError{Err: r}
}
}()

Expand All @@ -84,7 +80,7 @@ func (p *Participant) ReceiveECChain(chain ECChain) (err error) {
func (p *Participant) ValidateMessage(msg *GMessage) (checked bool, err error) {
defer func() {
if r := recover(); r != nil {
err = &PanicError{Err: err}
err = &PanicError{Err: r}
}
}()

Expand All @@ -106,7 +102,7 @@ func (p *Participant) ValidateMessage(msg *GMessage) (checked bool, err error) {
func (p *Participant) ReceiveMessage(msg *GMessage) (accepted bool, err error) {
defer func() {
if r := recover(); r != nil {
err = &PanicError{Err: err}
err = &PanicError{Err: r}
}
}()

Expand All @@ -126,7 +122,7 @@ func (p *Participant) ReceiveMessage(msg *GMessage) (accepted bool, err error) {
func (p *Participant) ReceiveAlarm() (err error) {
defer func() {
if r := recover(); r != nil {
err = &PanicError{Err: err}
err = &PanicError{Err: r}
}
}()

Expand Down
4 changes: 3 additions & 1 deletion sim/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ func (n *Network) Tick(adv AdversaryReceiver) (bool, error) {
}

msg := n.queue.Remove(i)
n.clock = msg.deliverAt
if msg.deliverAt.After(n.clock) {
n.clock = msg.deliverAt
}
payloadStr, ok := msg.payload.(string)
receiver := n.participants[msg.dest]
if ok && strings.HasPrefix(payloadStr, "ALARM") {
Expand Down
2 changes: 1 addition & 1 deletion test/honest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestSyncHalvesBLS(t *testing.T) {

func TestAsyncHalves(t *testing.T) {
t.Parallel()
for n := 4; n <= 2; n += 2 {
for n := 4; n <= 20; n += 2 {
for i := 0; i < ASYNC_ITERS; i++ {
sm := sim.NewSimulation(newAsyncConfig(n, i), GraniteConfig(), sim.TraceNone)
a := sm.Base(0).Extend(sm.CIDGen.Sample())
Expand Down

0 comments on commit 0e2629c

Please sign in to comment.