Skip to content

Commit

Permalink
Initialize the accountUpdatesLedgerEvaluator properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Aug 24, 2022
1 parent 87867c9 commit 43adafb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
25 changes: 25 additions & 0 deletions ledger/internal/apptxn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3295,3 +3295,28 @@ done:
require.Equal(t, "Y", vb.Block().Payset[3].EvalDelta.LocalDeltas[1]["X"].Bytes)
})
}

// TestReloadWithTxns confirms that the ledger can be reloaded from "disk" when
// doing so requires replaying some interesting AVM txns.
func TestReloadWithTxns(t *testing.T) {
partitiontest.PartitionTest(t)

genBalances, addrs, _ := ledgertesting.NewTestGenesis()
testConsensusRange(t, 34, 0, func(t *testing.T, ver int) {
fmt.Printf("testConsensus %d\n", ver)
dl := NewDoubleLedger(t, genBalances, consensusByNumber[ver])
defer dl.Close()

dl.fullBlock() // So that the `block` opcode has a block to inspect

lookHdr := txntest.Txn{
Type: "appl",
Sender: addrs[0],
ApprovalProgram: "txn FirstValid; int 1; -; block BlkTimestamp",
}

dl.fullBlock(&lookHdr)

dl.reloadLedgers()
})
}
5 changes: 5 additions & 0 deletions ledger/internal/double_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ func (dl *DoubleLedger) endBlock() *ledgercore.ValidatedBlock {
return vb
}

func (dl *DoubleLedger) reloadLedgers() {
require.NoError(dl.t, dl.generator.ReloadLedger())
require.NoError(dl.t, dl.validator.ReloadLedger())
}

func checkBlock(t *testing.T, checkLedger *ledger.Ledger, vb *ledgercore.ValidatedBlock) {
bl := vb.Block()
msg := bl.MarshalMsg(nil)
Expand Down
6 changes: 6 additions & 0 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ func OpenLedger(
return l, nil
}

// ReloadLedger is exported for the benefit of tests in the internal
// package. Revisit this when we rename / restructure that thing
func (l *Ledger) ReloadLedger() error {
return l.reloadLedger()
}

func (l *Ledger) reloadLedger() error {
// similar to the Close function, we want to start by closing the blockQ first. The
// blockQ is having a sync goroutine which indirectly calls other trackers. We want to eliminate that go-routine first,
Expand Down
5 changes: 3 additions & 2 deletions ledger/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,9 @@ func (tr *trackerRegistry) replay(l ledgerForTracker) (err error) {
}

accLedgerEval := accountUpdatesLedgerEvaluator{
au: tr.accts,
ao: tr.acctsOnline,
au: tr.accts,
ao: tr.acctsOnline,
tail: tr.tail,
}

if lastBalancesRound < lastestBlockRound {
Expand Down

0 comments on commit 43adafb

Please sign in to comment.