@@ -192,10 +192,14 @@ type testLedger struct {
192
192
certs map [basics.Round ]Certificate
193
193
nextRound basics.Round
194
194
195
+ maxNumBlocks uint64
196
+
195
197
// constant
196
198
state map [basics.Address ]basics.AccountData
197
199
198
200
notifications map [basics.Round ]signal
201
+
202
+ consensusVersion func (basics.Round ) (protocol.ConsensusVersion , error )
199
203
}
200
204
201
205
func makeTestLedger (state map [basics.Address ]basics.AccountData ) Ledger {
@@ -204,13 +208,54 @@ func makeTestLedger(state map[basics.Address]basics.AccountData) Ledger {
204
208
l .certs = make (map [basics.Round ]Certificate )
205
209
l .nextRound = 1
206
210
207
- // deep copy of state
208
211
l .state = make (map [basics.Address ]basics.AccountData )
209
212
for k , v := range state {
210
213
l .state [k ] = v
211
214
}
212
215
213
216
l .notifications = make (map [basics.Round ]signal )
217
+
218
+ l .consensusVersion = func (r basics.Round ) (protocol.ConsensusVersion , error ) {
219
+ return protocol .ConsensusCurrentVersion , nil
220
+ }
221
+ return l
222
+ }
223
+
224
+ func makeTestLedgerWithConsensusVersion (state map [basics.Address ]basics.AccountData , consensusVersion func (basics.Round ) (protocol.ConsensusVersion , error )) Ledger {
225
+ l := new (testLedger )
226
+ l .entries = make (map [basics.Round ]bookkeeping.Block )
227
+ l .certs = make (map [basics.Round ]Certificate )
228
+ l .nextRound = 1
229
+
230
+ l .state = make (map [basics.Address ]basics.AccountData )
231
+ for k , v := range state {
232
+ l .state [k ] = v
233
+ }
234
+
235
+ l .notifications = make (map [basics.Round ]signal )
236
+
237
+ l .consensusVersion = consensusVersion
238
+ return l
239
+ }
240
+
241
+ func makeTestLedgerMaxBlocks (state map [basics.Address ]basics.AccountData , maxNumBlocks uint64 ) Ledger {
242
+ l := new (testLedger )
243
+ l .entries = make (map [basics.Round ]bookkeeping.Block )
244
+ l .certs = make (map [basics.Round ]Certificate )
245
+ l .nextRound = 1
246
+
247
+ l .maxNumBlocks = maxNumBlocks
248
+
249
+ l .state = make (map [basics.Address ]basics.AccountData )
250
+ for k , v := range state {
251
+ l .state [k ] = v
252
+ }
253
+
254
+ l .notifications = make (map [basics.Round ]signal )
255
+
256
+ l .consensusVersion = func (r basics.Round ) (protocol.ConsensusVersion , error ) {
257
+ return protocol .ConsensusCurrentVersion , nil
258
+ }
214
259
return l
215
260
}
216
261
@@ -268,6 +313,10 @@ func (l *testLedger) LookupDigest(r basics.Round) (crypto.Digest, error) {
268
313
panic (err )
269
314
}
270
315
316
+ if l .maxNumBlocks != 0 && r + round (l .maxNumBlocks ) < l .nextRound {
317
+ return crypto.Digest {}, & LedgerDroppedRoundError {}
318
+ }
319
+
271
320
return l .entries [r ].Digest (), nil
272
321
}
273
322
@@ -279,6 +328,11 @@ func (l *testLedger) Lookup(r basics.Round, a basics.Address) (basics.AccountDat
279
328
err := fmt .Errorf ("Lookup called on future round: %v >= %v! (this is probably a bug)" , r , l .nextRound )
280
329
panic (err )
281
330
}
331
+
332
+ if l .maxNumBlocks != 0 && r + round (l .maxNumBlocks ) < l .nextRound {
333
+ return basics.AccountData {}, & LedgerDroppedRoundError {}
334
+ }
335
+
282
336
return l .state [a ], nil
283
337
}
284
338
@@ -348,11 +402,15 @@ func (l *testLedger) EnsureDigest(c Certificate, verifier *AsyncVoteVerifier) {
348
402
}
349
403
350
404
func (l * testLedger ) ConsensusParams (r basics.Round ) (config.ConsensusParams , error ) {
351
- return config .Consensus [protocol .ConsensusCurrentVersion ], nil
405
+ version , err := l .ConsensusVersion (r )
406
+ if err != nil {
407
+ return config.ConsensusParams {}, err
408
+ }
409
+ return config .Consensus [version ], nil
352
410
}
353
411
354
412
func (l * testLedger ) ConsensusVersion (r basics.Round ) (protocol.ConsensusVersion , error ) {
355
- return protocol . ConsensusCurrentVersion , nil
413
+ return l . consensusVersion ( r )
356
414
}
357
415
358
416
// simulation helpers
0 commit comments