Skip to content

Commit

Permalink
Prefetching for heartbeat transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
jannotti committed Nov 27, 2024
1 parent de1c241 commit 3a0abc4
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ledger/eval/prefetcher/prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,9 @@ func (p *accountPrefetcher) prefetch(ctx context.Context) {
// since they might be non-used arbitrary values

case protocol.StateProofTx:
case protocol.KeyRegistrationTx:
case protocol.KeyRegistrationTx: // No extra accounts besides the sender
case protocol.HeartbeatTx:
loadAccountsAddAccountTask(&stxn.Txn.HbAddress, task, accountTasks, queue)
}

// If you add new addresses here, also add them in getTxnAddresses().
Expand Down
52 changes: 52 additions & 0 deletions ledger/eval/prefetcher/prefetcher_alignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/algorand/go-algorand/crypto/stateproof"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/committee"
"github.com/algorand/go-algorand/data/stateproofmsg"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/ledger/eval"
Expand Down Expand Up @@ -1422,3 +1423,54 @@ func TestEvaluatorPrefetcherAlignmentStateProof(t *testing.T) {
prefetched.pretend(rewardsPool())
require.Equal(t, requested, prefetched)
}

func TestEvaluatorPrefetcherAlignmentHeartbeat(t *testing.T) {
partitiontest.PartitionTest(t)

// We need valid part keys to evaluate the Heartbeat.
const kd = 10
firstID := basics.OneTimeIDForRound(0, kd)
otss := crypto.GenerateOneTimeSignatureSecrets(firstID.Batch, 5)

l := &prefetcherAlignmentTestLedger{
balances: map[basics.Address]ledgercore.AccountData{
rewardsPool(): {
AccountBaseData: ledgercore.AccountBaseData{
MicroAlgos: basics.MicroAlgos{Raw: 1234567890},
},
},
makeAddress(1): {
AccountBaseData: ledgercore.AccountBaseData{
MicroAlgos: basics.MicroAlgos{Raw: 1000001},
},
},
makeAddress(2): {
AccountBaseData: ledgercore.AccountBaseData{
MicroAlgos: basics.MicroAlgos{Raw: 100_000},
},
VotingData: basics.VotingData{
VoteID: otss.OneTimeSignatureVerifier,
},
},
},
}

txn := transactions.Transaction{
Type: protocol.HeartbeatTx,
Header: transactions.Header{
Sender: makeAddress(1),
GenesisHash: genesisHash(),
Fee: basics.Algos(1), // Heartbeat txn is unusual in that it checks fees a bit.
},
HeartbeatTxnFields: transactions.HeartbeatTxnFields{
HbAddress: makeAddress(2),
HbProof: otss.Sign(firstID, committee.Seed(genesisHash())).ToHeartbeatProof(),
HbSeed: committee.Seed(genesisHash()),
},
}

requested, prefetched := run(t, l, txn)

prefetched.pretend(rewardsPool())
require.Equal(t, requested, prefetched)
}

0 comments on commit 3a0abc4

Please sign in to comment.