Skip to content

Commit

Permalink
fix: bail properly when budget exceeded
Browse files Browse the repository at this point in the history
This is only for the budget=0 case, since the >- budget case is handled
inside the go-ipld-prime traverser. Unlikely to see this in real-world usage.
  • Loading branch information
rvagg committed Oct 25, 2021
1 parent c96b3b2 commit 6c0156c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions ipldutil/traverser.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ func (t *traverser) start() {
t.budget.LinkBudget--
if t.budget.LinkBudget <= 0 {
t.writeDone(&traversal.ErrBudgetExceeded{BudgetKind: "link", Link: t.root})
return
}
}
nd, err := t.linkSystem.Load(ipld.LinkContext{Ctx: t.ctx}, t.root, ns)
Expand Down
4 changes: 2 additions & 2 deletions ipldutil/traverser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestTraverser(t *testing.T) {
testutil.AssertDoesReceive(ctx, t, done, "should have completed verification but did not")
})

t.Run("errors correctly, with budget", func(t *testing.T) {
t.Run("errors correctly, data with budget", func(t *testing.T) {
store := make(map[ipld.Link][]byte)
persistence := testutil.NewTestStore(store)
blockChain := testutil.SetupBlockChain(ctx, t, persistence, 100, 10)
Expand All @@ -117,7 +117,7 @@ func TestTraverser(t *testing.T) {
checkTraverseSequence(ctx, t, traverser, blockChain.Blocks(0, 6), &traversal.ErrBudgetExceeded{BudgetKind: "link", Path: path, Link: blockChain.LinkTipIndex(6)})
})

t.Run("errors correctly, no budget", func(t *testing.T) {
t.Run("errors correctly, with zero budget", func(t *testing.T) {
store := make(map[ipld.Link][]byte)
persistence := testutil.NewTestStore(store)
blockChain := testutil.SetupBlockChain(ctx, t, persistence, 100, 10)
Expand Down

0 comments on commit 6c0156c

Please sign in to comment.