-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prefetcher: improve error codes #3815
Changes from 1 commit
b44a698
ea7d889
1872f24
12cc554
b1775dc
8b16d9c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ package prefetcher_test | |
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
@@ -50,9 +51,10 @@ func makeAddress(addressSeed int) (o basics.Address) { | |
const proto = protocol.ConsensusCurrentVersion | ||
|
||
type prefetcherTestLedger struct { | ||
round basics.Round | ||
balances map[basics.Address]ledgercore.AccountData | ||
creators map[basics.CreatableIndex]basics.Address | ||
round basics.Round | ||
balances map[basics.Address]ledgercore.AccountData | ||
creators map[basics.CreatableIndex]basics.Address | ||
errorAddress map[basics.Address]bool | ||
} | ||
|
||
func (l *prefetcherTestLedger) BlockHdr(basics.Round) (bookkeeping.BlockHeader, error) { | ||
|
@@ -61,7 +63,10 @@ func (l *prefetcherTestLedger) BlockHdr(basics.Round) (bookkeeping.BlockHeader, | |
func (l *prefetcherTestLedger) CheckDup(config.ConsensusParams, basics.Round, basics.Round, basics.Round, transactions.Txid, ledgercore.Txlease) error { | ||
return nil | ||
} | ||
func (l *prefetcherTestLedger) LookupWithoutRewards(_ basics.Round, addr basics.Address) (ledgercore.AccountData, basics.Round, error) { | ||
func (l *prefetcherTestLedger) LookupWithoutRewards(rnd basics.Round, addr basics.Address) (ledgercore.AccountData, basics.Round, error) { | ||
if _, has := l.errorAddress[addr]; has { | ||
return ledgercore.AccountData{}, l.round, fmt.Errorf("Lookup Error") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you might want to use a custom error type here so that you could make |
||
} | ||
if data, has := l.balances[addr]; has { | ||
return data, l.round, nil | ||
} | ||
|
@@ -71,9 +76,15 @@ func (l *prefetcherTestLedger) LookupApplication(rnd basics.Round, addr basics.A | |
return ledgercore.AppResource{}, nil | ||
} | ||
func (l *prefetcherTestLedger) LookupAsset(rnd basics.Round, addr basics.Address, aidx basics.AssetIndex) (ledgercore.AssetResource, error) { | ||
if aidx > 1000000 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instead of using a threshold, make a given asset index invalid ( i.e. |
||
return ledgercore.AssetResource{}, fmt.Errorf("Asset Lookup Error") | ||
} | ||
return ledgercore.AssetResource{}, nil | ||
} | ||
func (l *prefetcherTestLedger) GetCreatorForRound(_ basics.Round, cidx basics.CreatableIndex, _ basics.CreatableType) (basics.Address, bool, error) { | ||
if cidx > 1000000 { | ||
return basics.Address{}, false, fmt.Errorf("Get Creator Error") | ||
} | ||
if addr, has := l.creators[cidx]; has { | ||
return addr, true, nil | ||
} | ||
|
@@ -151,16 +162,17 @@ func compareLoadedResourcesEntries(t *testing.T, expected []prefetcher.LoadedRes | |
require.Equal(t, expectedForTest, actualForTest) | ||
} | ||
|
||
func TestEvaluatorPrefetcher(t *testing.T) { | ||
func TestEvaluatorPrefetcherX(t *testing.T) { | ||
partitiontest.PartitionTest(t) | ||
|
||
rnd := basics.Round(5) | ||
var feeSinkAddr = basics.Address{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} | ||
|
||
var ledger = &prefetcherTestLedger{ | ||
round: rnd, | ||
balances: make(map[basics.Address]ledgercore.AccountData), | ||
creators: make(map[basics.CreatableIndex]basics.Address), | ||
round: rnd, | ||
balances: make(map[basics.Address]ledgercore.AccountData), | ||
creators: make(map[basics.CreatableIndex]basics.Address), | ||
errorAddress: make(map[basics.Address]bool), | ||
} | ||
ledger.balances[makeAddress(1)] = ledgercore.AccountData{ | ||
AccountBaseData: ledgercore.AccountBaseData{MicroAlgos: basics.MicroAlgos{Raw: 100000000}}, | ||
|
@@ -493,6 +505,85 @@ func TestEvaluatorPrefetcher(t *testing.T) { | |
require.False(t, ok) | ||
}) | ||
} | ||
|
||
// Test for the GroupIdx in the returned error | ||
tc := testCases[3] | ||
t.Run(tc.name, func(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if you're repeating the same test case name, please have this implemented in a separate Test function. |
||
errorReceived := false | ||
groups := make([][]transactions.SignedTxnWithAD, 5) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that this test would be much more readable if you'll use explicit use cases ( as above ), instead of programmatically modifying the test cases. |
||
for i := 0; i < 5; i++ { | ||
groups[i] = make([]transactions.SignedTxnWithAD, 2) | ||
for j := 0; j < 2; j++ { | ||
groups[i][j].SignedTxn = tc.signedTxn | ||
if tc.signedTxn.Txn.Type == protocol.AssetTransferTx { | ||
if i == 2 { | ||
// force error in asset lookup | ||
groups[i][j].SignedTxn.Txn.AssetTransferTxnFields.XferAsset = 1000001 | ||
} | ||
} | ||
} | ||
} | ||
preloadedTxnGroupsCh := prefetcher.PrefetchAccounts(context.Background(), ledger, rnd+100, groups, feeSinkAddr, config.Consensus[proto]) | ||
for loadedTxnGroup := range preloadedTxnGroupsCh { | ||
if err, ok := loadedTxnGroup.Err.(ledgercore.GroupTaskError); ok { | ||
errorReceived = true | ||
require.Equal(t, int64(2), err.GroupIdx) | ||
} | ||
} | ||
require.True(t, errorReceived) | ||
}) | ||
|
||
tc = testCases[2] | ||
errorReceived := false | ||
// Test for errors generated from GetCreatorForRound | ||
t.Run(tc.name, func(t *testing.T) { | ||
groups := make([][]transactions.SignedTxnWithAD, 5) | ||
for i := 0; i < 5; i++ { | ||
groups[i] = make([]transactions.SignedTxnWithAD, 10) | ||
for j := 0; j < 10; j++ { | ||
groups[i][j].SignedTxn = tc.signedTxn | ||
if tc.signedTxn.Txn.AssetConfigTxnFields.ConfigAsset > 0 { | ||
// creatable index | ||
tc.signedTxn.Txn.AssetConfigTxnFields.ConfigAsset = 1000001 | ||
} | ||
} | ||
} | ||
preloadedTxnGroupsCh := prefetcher.PrefetchAccounts(context.Background(), ledger, rnd+100, groups, feeSinkAddr, config.Consensus[proto]) | ||
|
||
for loadedTxnGroup := range preloadedTxnGroupsCh { | ||
if err, ok := loadedTxnGroup.Err.(ledgercore.GroupTaskError); ok { | ||
errorReceived = true | ||
fmt.Println(err) | ||
} | ||
} | ||
require.True(t, errorReceived) | ||
}) | ||
|
||
// Test for errors generated from LookupWithoutRewards | ||
errorReceived = false | ||
t.Run(tc.name, func(t *testing.T) { | ||
groups := make([][]transactions.SignedTxnWithAD, 5) | ||
for i := 0; i < 5; i++ { | ||
groups[i] = make([]transactions.SignedTxnWithAD, 10) | ||
for j := 0; j < 10; j++ { | ||
groups[i][j].SignedTxn = tc.signedTxn | ||
if i > 3 && j > 7 { | ||
// force lookup error | ||
ledger.errorAddress[groups[i][j].SignedTxn.Txn.Sender] = true | ||
} | ||
} | ||
} | ||
preloadedTxnGroupsCh := prefetcher.PrefetchAccounts(context.Background(), ledger, rnd+100, groups, feeSinkAddr, config.Consensus[proto]) | ||
|
||
for loadedTxnGroup := range preloadedTxnGroupsCh { | ||
if err, ok := loadedTxnGroup.Err.(ledgercore.GroupTaskError); ok { | ||
errorReceived = true | ||
fmt.Println(err) | ||
} | ||
} | ||
require.True(t, errorReceived) | ||
}) | ||
|
||
} | ||
|
||
func TestEvaluatorPrefetcherQueueExpansion(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,3 +107,14 @@ type ErrNonSequentialBlockEval struct { | |
func (err ErrNonSequentialBlockEval) Error() string { | ||
return fmt.Sprintf("block evaluation for round %d requires sequential evaluation while the latest round is %d", err.EvaluatorRound, err.LatestRound) | ||
} | ||
|
||
// GroupTaskError indicates the group index of the unfulfilled resource | ||
type GroupTaskError struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. two requests:
|
||
Err error | ||
GroupIdx int64 | ||
} | ||
|
||
// Error satisfies builtin interface `error` | ||
func (err GroupTaskError) Error() string { | ||
return fmt.Sprintf("Prefetch failed for groupIdx %d cause: %v", err.GroupIdx, err.Err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your change, the Err is always either of type
ledgercore.GroupTaskError
ornil
. It sounds as if you should change theErr
datatype to be*GroupTaskError
.