Skip to content

Commit

Permalink
minor corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
beer-1 committed Jan 7, 2025
1 parent 439ca3b commit 84f9f73
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 10 deletions.
6 changes: 3 additions & 3 deletions challenger/eventhandler/challenge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func TestCheckValue(t *testing.T) {

ctx := types.NewContext(context.Background(), zap.NewNop(), "")

challenges, procesedEvents, err := eventHandler.CheckValue(ctx, checkingEvents)
challenges, processedEvents, err := eventHandler.CheckValue(ctx, checkingEvents)
require.NoError(t, err)

require.Len(t, challenges, 2)
require.Len(t, procesedEvents, 4)
require.Len(t, processedEvents, 4)

require.Equal(t, challenges[0].Id, challengertypes.ChallengeId{Type: challengertypes.EventTypeOracle, Id: 4})
require.Equal(t, challenges[1].Id, challengertypes.ChallengeId{Type: challengertypes.EventTypeOutput, Id: 2})

require.ElementsMatch(t, procesedEvents, append(events[:1], events[2:]...))
require.ElementsMatch(t, processedEvents, append(events[:1], events[2:]...))
}

func TestGetPrevPendingEvent(t *testing.T) {
Expand Down
3 changes: 2 additions & 1 deletion challenger/eventhandler/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func GetPendingEvent(db types.BasicDB, id challengertypes.ChallengeId) (challeng
if err != nil {
return nil, errors.Wrap(err, "failed to unmarshal challenge event")
}
return event, err

return event, nil
}

func SavePendingEvents(db types.BasicDB, events []challengertypes.ChallengeEvent) error {
Expand Down
4 changes: 2 additions & 2 deletions challenger/eventhandler/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestDBPendingEvent(t *testing.T) {
db, err := db.NewMemDB()
require.NoError(t, err)

event := challengertypes.NewDeposit(1, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 10000))
event := challengertypes.NewDeposit(1, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 10000).UTC())

_, err = GetPendingEvent(db, event.Id())
require.Error(t, err)
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestDBPendingEvents(t *testing.T) {
var ids []challengertypes.ChallengeId

for i := uint64(0); i < 10; i++ {
event := challengertypes.NewDeposit(i, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 10000))
event := challengertypes.NewDeposit(i, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 10000).UTC())
events = append(events, event)
ids = append(ids, event.Id())
}
Expand Down
5 changes: 5 additions & 0 deletions challenger/eventhandler/pending_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
)

func (ch *ChallengeEventHandler) SetPendingEvents(events []challengertypes.ChallengeEvent) {
if len(events) == 0 {
return
}

ch.pendingEventsMu.Lock()
defer ch.pendingEventsMu.Unlock()

Expand Down Expand Up @@ -40,6 +44,7 @@ func (ch *ChallengeEventHandler) DeletePendingEvent(id challengertypes.Challenge
delete(ch.pendingEvents, id)
}

// get all pending oracle events that are less than toL1BlockHeight
func (ch *ChallengeEventHandler) getOraclePendingEvents(toL1BlockHeight uint64) []challengertypes.ChallengeEvent {
ch.pendingEventsMu.Lock()
defer ch.pendingEventsMu.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions challenger/eventhandler/pending_events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func TestPendingEvent(t *testing.T) {
eventHandler := NewChallengeEventHandler(db)

events := []challengertypes.ChallengeEvent{
challengertypes.NewDeposit(1, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 100)),
challengertypes.NewDeposit(2, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 101)),
challengertypes.NewOracle(3, []byte("data"), time.Unix(0, 103)),
challengertypes.NewOracle(4, []byte("data2"), time.Unix(0, 104)),
challengertypes.NewDeposit(1, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 100).UTC()),
challengertypes.NewDeposit(2, 2, "from", "to", "l1Denom", "amount", time.Unix(0, 101).UTC()),
challengertypes.NewOracle(3, []byte("data"), time.Unix(0, 103).UTC()),
challengertypes.NewOracle(4, []byte("data2"), time.Unix(0, 104).UTC()),
}

eventHandler.SetPendingEvents(events)
Expand Down
1 change: 1 addition & 0 deletions challenger/host/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestBeginBlockHandler(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 1, h.stage.Len())

// clear eventQueue, outputPendingEventQueue and stage
err = h.beginBlockHandler(types.Context{}, nodetypes.BeginBlockArgs{})
require.NoError(t, err)

Expand Down
3 changes: 3 additions & 0 deletions challenger/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ func (h *Host) Initialize(ctx types.Context, processedHeight int64, child childN
h.child = child
h.challenger = challenger

// fetch next l1 sequence to process, we don't need to process previous l1 sequences
// because they are already processed by the challenger.
h.initialL1Sequence, err = h.child.QueryNextL1Sequence(ctx, h.child.Height())
if err != nil {
return time.Time{}, errors.Wrap(err, "failed to query next l1 sequence")
}

h.registerHandlers()

err = h.eventHandler.Initialize(bridgeInfo.BridgeConfig.SubmissionInterval)
Expand Down

0 comments on commit 84f9f73

Please sign in to comment.