Skip to content

Commit

Permalink
tests: ledger reload accessing txtail history (algorand#4473)
Browse files Browse the repository at this point in the history
* Ensure blk opcode can be replayed after restart
* Fix e2e fast catchup tests
  • Loading branch information
algorandskiy authored and onetechnical committed Aug 26, 2022
1 parent 339db4e commit 5e794c1
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ledger/applications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ import (
// commitRound schedules a commit for known offset and dbRound
// and waits for completion
func commitRound(offset uint64, dbRound basics.Round, l *Ledger) {
commitRoundLookback(dbRound+basics.Round(offset), l)
commitRoundLookback(l.Latest().SubSaturate(dbRound+basics.Round(offset)), l)
}

func commitRoundLookback(lookback basics.Round, l *Ledger) {
l.trackers.mu.Lock()
l.trackers.lastFlushTime = time.Time{}
l.trackers.mu.Unlock()

l.trackers.scheduleCommit(l.Latest(), l.Latest()-lookback)
l.trackers.scheduleCommit(l.Latest(), lookback)
// wait for the operation to complete. Once it does complete, the tr.lastFlushTime is going to be updated, so we can
// use that as an indicator.
for {
Expand Down
24 changes: 22 additions & 2 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,8 @@ int %d // 10001000
require.NoError(t, err)

blk.BlockHeader.Round++
blk.BlockHeader.TimeStamp += 1
blk.TxnCounter += 1
blk.BlockHeader.TimeStamp++
blk.TxnCounter++
blk.Payset = append(blk.Payset, txib)
blk.TxnCommitments, err = blk.PaysetCommit()
require.NoError(t, err)
Expand All @@ -2351,6 +2351,26 @@ int %d // 10001000

latest := l.Latest()
require.Equal(t, basics.Round(2*proto.MaxTxnLife+1), latest)

// add couple more blocks to have the block with `blk BlkTimestamp` to be dbRound + 1
// reload again and ensure this block can be replayed
programRound := blk.BlockHeader.Round
target := latest + basics.Round(cfg.MaxAcctLookback) - 1
blk = genesisInitState.Block
blk.BlockHeader.Round = latest
for i := latest + 1; i <= target; i++ {
blk.BlockHeader.Round++
blk.BlockHeader.TimeStamp = roundToTimeStamp(int(i))
err = l.AddBlock(blk, agreement.Certificate{})
require.NoError(t, err)
}

commitRoundLookback(basics.Round(cfg.MaxAcctLookback), l)
l.trackers.mu.RLock()
require.Equal(t, programRound, l.trackers.dbRound+1) // programRound is next to be replayed
l.trackers.mu.RUnlock()
err = l.reloadLedger()
require.NoError(t, err)
}

// TestLedgerMigrateV6ShrinkDeltas opens a ledger + dbV6, submits a bunch of txns,
Expand Down
1 change: 0 additions & 1 deletion ledger/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import (

// commitRoundNext schedules a commit with as many rounds as possible
func commitRoundNext(l *Ledger) {
// maxAcctLookback := l.trackers.cfg.MaxAcctLookback
maxAcctLookback := 320
commitRoundLookback(basics.Round(maxAcctLookback), l)
}
Expand Down
6 changes: 3 additions & 3 deletions test/e2e-go/cli/goal/expect/catchpointCatchupTest.exp
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ if { [catch {

# Wait until the primary node reaches round 37. At that point, the catchpoint for round 36 is already done.
# The rationale is the following:
# 1. MaxTxnLife = 33 so catchup would load blocks 3..36
# 1. MaxTxnLife = 23 and CatchpointLookback = 8 so catchup would load blocks 36-8-23..36 = 5..36
# 2. Loading block 2 is blocked by the catchpoint proxy
# 3. Next block is 37 that would require balances from round 37-MaxBalLookback = 5 to be accessed, and this is
# within the expected range of 3...36
# 3. Next block is 37 that would require balances from round 37-MaxBalLookback = 29 to be accessed, and this is
# within the expected range of 5...36
::AlgorandGoal::WaitForRound 37 $TEST_ROOT_DIR/Primary

# Get primary node listening address:
Expand Down
11 changes: 7 additions & 4 deletions test/e2e-go/features/catchup/catchpointCatchup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,14 @@ func TestBasicCatchpointCatchup(t *testing.T) {

// Let the network make some progress
currentRound := uint64(1)
// fast catchup downloads some blocks back from catchpoint round - CatchpointLookback
expectedBlocksToDownload := catchpointCatchupProtocol.MaxTxnLife + catchpointCatchupProtocol.DeeperBlockHeaderHistory
const restrictedBlock = 2 // block number that is rejected to be downloaded to ensure fast catchup and not regular catchup is running
// calculate the target round: this is the next round after catchpoint that is greater than expectedBlocksToDownload before the restrictedBlock block number
targetCatchpointRound := (basics.Round(expectedBlocksToDownload+restrictedBlock)/catchpointInterval + 1) * catchpointInterval
targetRound := uint64(targetCatchpointRound) + 1 // 21
const restrictedBlockRound = 2 // block number that is rejected to be downloaded to ensure fast catchup and not regular catchup is running
// calculate the target round: this is the next round after catchpoint
// that is greater than expectedBlocksToDownload before the restrictedBlock block number
minRound := restrictedBlockRound + catchpointCatchupProtocol.CatchpointLookback
targetCatchpointRound := (basics.Round(expectedBlocksToDownload+minRound)/catchpointInterval + 1) * catchpointInterval
targetRound := uint64(targetCatchpointRound) + 1
primaryNodeRestClient := fixture.GetAlgodClientForController(primaryNode)
primaryNodeRestClient.SetAPIVersionAffinity(algodclient.APIVersionV2)
log.Infof("Building ledger history..")
Expand Down
8 changes: 4 additions & 4 deletions test/testdata/consensus/catchpointtestingprotocol.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"MaxAssetURLBytes": 96,
"MaxAssetUnitNameBytes": 8,
"MaxAssetsPerAccount": 1000,
"MaxBalLookback": 32,
"CatchpointLookback": 32,
"MaxBalLookback": 8,
"CatchpointLookback": 8,
"MaxExtraAppProgramPages": 3,
"MaxGlobalSchemaEntries": 64,
"MaxInnerTransactions": 16,
Expand All @@ -65,7 +65,7 @@
"MaxTimestampIncrement": 25,
"MaxTxGroupSize": 16,
"MaxTxnBytesPerBlock": 1000000,
"MaxTxnLife": 33,
"MaxTxnLife": 23,
"MaxTxnNoteBytes": 1024,
"MaxUpgradeWaitRounds": 150000,
"MaxVersionStringLen": 128,
Expand All @@ -89,7 +89,7 @@
"SchemaMinBalancePerEntry": 25000,
"SchemaUintMinBalance": 3500,
"SeedLookback": 2,
"SeedRefreshInterval": 8,
"SeedRefreshInterval": 2,
"SoftCommitteeSize": 2990,
"SoftCommitteeThreshold": 2267,
"SupportBecomeNonParticipatingTransactions": true,
Expand Down

0 comments on commit 5e794c1

Please sign in to comment.