From 49c47180328c06eaeaca9176c2819b55bd75464f Mon Sep 17 00:00:00 2001 From: Mission Liao Date: Fri, 22 Mar 2019 14:04:30 +0800 Subject: core: height event handlers are not called (#509) * Make utils.RoundEvent.ValidateNextRound non-blocking * Make NotifyHeight called blockingly * Trigger all height event handlers that should be triggered by initBlock * Fixup: forget the syncer part --- core/test/app.go | 13 ++++--------- core/test/app_test.go | 3 ++- 2 files changed, 6 insertions(+), 10 deletions(-) (limited to 'core/test') diff --git a/core/test/app.go b/core/test/app.go index 12b2047..d704698 100644 --- a/core/test/app.go +++ b/core/test/app.go @@ -108,18 +108,13 @@ func NewApp(initRound uint64, gov *Governance, rEvt *utils.RoundEvent) ( app.state = gov.State() } if rEvt != nil { - app.hEvt.RegisterHeight( - utils.GetNextRoundValidationHeight(rEvt.LastPeriod()), - func(h uint64) { - rEvt.ValidateNextRound(h) - }) rEvt.Register(func(evts []utils.RoundEventParam) { app.hEvt.RegisterHeight( evts[len(evts)-1].NextRoundValidationHeight(), - func(h uint64) { - rEvt.ValidateNextRound(h) - }) + utils.RoundEventRetryHandlerGenerator(rEvt, app.hEvt), + ) }) + rEvt.TriggerInitEvent() } return app } @@ -265,7 +260,7 @@ func (app *App) BlockDelivered(blockHash common.Hash, pos types.Position, } } }() - go app.hEvt.NotifyHeight(result.Height) + app.hEvt.NotifyHeight(result.Height) } // GetLatestDeliveredPosition would return the latest position of delivered diff --git a/core/test/app_test.go b/core/test/app_test.go index 138f803..e06b758 100644 --- a/core/test/app_test.go +++ b/core/test/app_test.go @@ -309,7 +309,7 @@ func (s *AppTestSuite) TestAttachedWithRoundEvent() { 1900, 2019, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. - evts := make(chan evtParamToCheck, 2) + evts := make(chan evtParamToCheck, 3) rEvt.Register(func(params []utils.RoundEventParam) { for _, p := range params { evts <- evtParamToCheck{ @@ -336,6 +336,7 @@ func (s *AppTestSuite) TestAttachedWithRoundEvent() { // Deliver blocks from height=2020 to height=2081. deliver(0, 0, 2019) deliver(19, 2020, 2091) + s.Require().Equal(<-evts, evtParamToCheck{19, 1, 2000, gov.CRS(19)}) s.Require().Equal(<-evts, evtParamToCheck{19, 2, 2100, gov.CRS(19)}) s.Require().Equal(<-evts, evtParamToCheck{20, 0, 2200, gov.CRS(20)}) // Deliver blocks from height=2082 to height=2281. -- cgit v1.2.3