Skip to content

Commit f8e2d54

Browse files
author
Naohiro Yoshida
committed
check strict
Signed-off-by: Naohiro Yoshida <[email protected]>
1 parent bd5b4cf commit f8e2d54

File tree

3 files changed

+40
-17
lines changed

3 files changed

+40
-17
lines changed

module/prover.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,21 @@ func (pr *Prover) getForkParameters() []*ForkSpec {
237237
}
238238

239239
func (pr *Prover) buildInitialState(dstHeader core.Header) (exported.ClientState, exported.ConsensusState, error) {
240+
241+
// Last ForkSpec must have height or CreateClient is less than fork spec timestamp
242+
forkSpecs := pr.getForkParameters()
243+
lastForkSpec := forkSpecs[len(forkSpecs)-1]
244+
lastForkSpecTime := lastForkSpec.GetHeightOrTimestamp().(*ForkSpec_Timestamp)
245+
if lastForkSpecTime != nil {
246+
target, err := dstHeader.(*Header).Target()
247+
if err != nil {
248+
return nil, nil, err
249+
}
250+
if MilliTimestamp(target) >= lastForkSpecTime.Timestamp {
251+
return nil, nil, fmt.Errorf("target timestamp is less than the last fork spec timestamp %d, %d", lastForkSpecTime.Timestamp, MilliTimestamp(target))
252+
}
253+
}
254+
240255
dstHeader, err := pr.withValidators(dstHeader.GetHeight().GetRevisionHeight(), dstHeader.(*Header).Headers)
241256
if err != nil {
242257
return nil, nil, err

module/setup.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ func setupHeadersForUpdate(
9393
logger.Info("Must set boundary timestamp", "ts", nextForkBoundaryTs, "nextForkBoundaryHeightMinus1", nextForkBoundaryHeightMinus1)
9494

9595
firstUnsaved := trustedEpochHeight + skip
96-
if firstUnsaved == savedLatestHeight {
96+
if firstUnsaved <= savedLatestHeight {
9797
firstUnsaved += skip
9898
}
9999

100-
submittingHeights := makeSubmittingHeights(latestFinalizedHeight, firstUnsaved, nextForkBoundaryTs, nextForkBoundaryHeightMinus1)
100+
submittingHeights := makeSubmittingHeights(latestFinalizedHeight, savedLatestHeight, firstUnsaved, nextForkBoundaryTs, nextForkBoundaryHeightMinus1)
101101
logger.Debug("submitting heights", "heights", submittingHeights)
102102

103103
trustedHeight := clientStateLatestHeight.GetRevisionHeight()
@@ -141,7 +141,7 @@ func withTrustedHeight(targetHeaders []core.Header, clientStateLatestHeight expo
141141
return targetHeaders
142142
}
143143

144-
func makeSubmittingHeights(latestFinalizedHeight uint64, firstUnsaved uint64, nextForkBoundaryTs *uint64, nextForkBoundaryHeightMinus1 uint64) []uint64 {
144+
func makeSubmittingHeights(latestFinalizedHeight uint64, savedLatestHeight uint64, firstUnsaved uint64, nextForkBoundaryTs *uint64, nextForkBoundaryHeightMinus1 uint64) []uint64 {
145145
var submittingHeights []uint64
146146
if latestFinalizedHeight < firstUnsaved {
147147
if nextForkBoundaryTs != nil && nextForkBoundaryHeightMinus1 < latestFinalizedHeight {
@@ -158,6 +158,10 @@ func makeSubmittingHeights(latestFinalizedHeight uint64, firstUnsaved uint64, ne
158158
if temp[i-1] < nextForkBoundaryHeightMinus1 && nextForkBoundaryHeightMinus1 < epochCandidate {
159159
submittingHeights = append(submittingHeights, nextForkBoundaryHeightMinus1)
160160
}
161+
} else if i == 0 {
162+
if savedLatestHeight < nextForkBoundaryHeightMinus1 && nextForkBoundaryHeightMinus1 < epochCandidate {
163+
submittingHeights = append(submittingHeights, nextForkBoundaryHeightMinus1)
164+
}
161165
}
162166
submittingHeights = append(submittingHeights, epochCandidate)
163167
}

module/setup_test.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -228,52 +228,56 @@ func (ts *SetupTestSuite) TestSuccess_setupHeadersForUpdate_withHFBoundary() {
228228
func (ts *SetupTestSuite) Test_makeSubmittingHeights() {
229229
rq := ts.Require()
230230
msec := uint64(0)
231-
rq.Len(makeSubmittingHeights(10, 11, nil, 0), 0)
232-
rq.Len(makeSubmittingHeights(10, 11, &msec, 11), 0)
233-
rq.Len(makeSubmittingHeights(10, 11, &msec, 9), 1)
231+
rq.Len(makeSubmittingHeights(10, 1, 11, nil, 0), 0)
232+
rq.Len(makeSubmittingHeights(10, 1, 11, &msec, 11), 0)
233+
rq.Len(makeSubmittingHeights(10, 1, 11, &msec, 9), 1)
234+
rq.Equal(
235+
[]uint64{99, 100, 200, 300, 400, 500},
236+
makeSubmittingHeights(501, 0, 100, &msec, 99),
237+
)
234238
rq.Equal(
235239
[]uint64{100, 200, 300, 400, 500},
236-
makeSubmittingHeights(501, 100, &msec, 99),
240+
makeSubmittingHeights(501, 101, 100, &msec, 99),
237241
)
238242
rq.Equal(
239243
[]uint64{100, 200, 300, 400, 500},
240-
makeSubmittingHeights(501, 100, &msec, 100),
244+
makeSubmittingHeights(501, 0, 100, &msec, 100),
241245
)
242246
rq.Equal(
243247
[]uint64{100, 101, 200, 300, 400, 500},
244-
makeSubmittingHeights(501, 100, &msec, 101),
248+
makeSubmittingHeights(501, 0, 100, &msec, 101),
245249
)
246250
rq.Equal(
247251
[]uint64{100, 200, 300, 400, 500},
248-
makeSubmittingHeights(501, 100, nil, 101),
252+
makeSubmittingHeights(501, 0, 100, nil, 101),
249253
)
250254
rq.Equal(
251255
[]uint64{100, 200, 201, 300, 400, 500},
252-
makeSubmittingHeights(501, 100, &msec, 201),
256+
makeSubmittingHeights(501, 0, 100, &msec, 201),
253257
)
254258
rq.Equal(
255259
[]uint64{100, 200, 300, 301, 400, 500},
256-
makeSubmittingHeights(501, 100, &msec, 301),
260+
makeSubmittingHeights(501, 0, 100, &msec, 301),
257261
)
258262
rq.Equal(
259263
[]uint64{100, 200, 300, 400, 401, 500},
260-
makeSubmittingHeights(501, 100, &msec, 401),
264+
makeSubmittingHeights(501, 0, 100, &msec, 401),
261265
)
262266
rq.Equal(
263267
[]uint64{100, 200, 300, 400, 500},
264-
makeSubmittingHeights(501, 100, nil, 401),
268+
makeSubmittingHeights(501, 0, 100, nil, 401),
265269
)
266270
rq.Equal(
267271
[]uint64{100, 200, 300, 400, 500},
268-
makeSubmittingHeights(501, 100, &msec, 501),
272+
makeSubmittingHeights(501, 0, 100, &msec, 501),
269273
)
270274
rq.Equal(
271275
[]uint64{100, 200, 300, 400, 500, 501},
272-
makeSubmittingHeights(502, 100, &msec, 501),
276+
makeSubmittingHeights(502, 0, 100, &msec, 501),
273277
)
274278
rq.Equal(
275279
[]uint64{100, 200, 300, 400, 500},
276-
makeSubmittingHeights(502, 100, nil, 501),
280+
makeSubmittingHeights(502, 0, 100, nil, 501),
277281
)
278282

279283
}

0 commit comments

Comments
 (0)