Skip to content

Commit 09341a6

Browse files
Active at tip failure
1 parent af9a251 commit 09341a6

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed

reconciler/reconciler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ const (
5353
// BacklogFull is when the reconciliation backlog is full.
5454
BacklogFull = "BACKLOG_FULL"
5555

56-
// TransientFailure is returned when looking up the live
56+
// TipFailure is returned when looking up the live
5757
// balance fails but we are at tip. This usually occurs
5858
// when the node processes an re-org that we have yet
5959
// to process (so the index we are querying at may be
6060
// ahead of the nodes tip).
61-
TransientFailure = "TRANSIENT_FAILURE"
61+
TipFailure = "TIP_FAILURE"
6262
)
6363

6464
const (
@@ -799,7 +799,7 @@ func (r *Reconciler) reconcileActiveAccounts(ctx context.Context) error { // nol
799799
ActiveReconciliation,
800800
balanceChange.Account,
801801
balanceChange.Currency,
802-
TransientFailure,
802+
TipFailure,
803803
); err != nil {
804804
return err
805805
}
@@ -930,7 +930,7 @@ func (r *Reconciler) reconcileInactiveAccounts(
930930
InactiveReconciliation,
931931
nextAcct.Entry.Account,
932932
nextAcct.Entry.Currency,
933-
TransientFailure,
933+
TipFailure,
934934
); err != nil {
935935
return err
936936
}

reconciler/reconciler_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,3 +2205,75 @@ func TestReconcile_EnqueueCancel(t *testing.T) {
22052205
mockHelper.AssertExpectations(t)
22062206
mockHandler.AssertExpectations(t)
22072207
}
2208+
2209+
func TestReconcile_ActiveAtTipError(t *testing.T) {
2210+
var (
2211+
block = &types.BlockIdentifier{
2212+
Hash: "block 1",
2213+
Index: 1,
2214+
}
2215+
accountCurrency = &types.AccountCurrency{
2216+
Account: &types.AccountIdentifier{
2217+
Address: "addr 1",
2218+
},
2219+
Currency: &types.Currency{
2220+
Symbol: "BTC",
2221+
Decimals: 8,
2222+
},
2223+
}
2224+
)
2225+
2226+
mockHelper := &mocks.Helper{}
2227+
mockHandler := &mocks.Handler{}
2228+
r := New(
2229+
mockHelper,
2230+
mockHandler,
2231+
nil,
2232+
WithActiveConcurrency(1),
2233+
WithInactiveConcurrency(0),
2234+
WithLookupBalanceByBlock(),
2235+
)
2236+
ctx := context.Background()
2237+
ctx, cancel := context.WithCancel(ctx)
2238+
2239+
mockHelper.On(
2240+
"LiveBalance",
2241+
mock.Anything,
2242+
accountCurrency.Account,
2243+
accountCurrency.Currency,
2244+
int64(1),
2245+
).Return(
2246+
nil,
2247+
nil,
2248+
errors.New("blah"),
2249+
).Once()
2250+
mockHelper.On("AtTip", mock.Anything).Return(true, nil).Once()
2251+
mockHandler.On(
2252+
"ReconciliationSkipped",
2253+
mock.Anything,
2254+
ActiveReconciliation,
2255+
accountCurrency.Account,
2256+
accountCurrency.Currency,
2257+
TipFailure,
2258+
).Return(nil).Once()
2259+
2260+
go func() {
2261+
err := r.Reconcile(ctx)
2262+
assert.True(t, errors.Is(err, context.Canceled))
2263+
}()
2264+
2265+
err := r.QueueChanges(ctx, block, []*parser.BalanceChange{
2266+
{
2267+
Account: accountCurrency.Account,
2268+
Currency: accountCurrency.Currency,
2269+
Block: block,
2270+
},
2271+
})
2272+
assert.NoError(t, err)
2273+
2274+
time.Sleep(1 * time.Second)
2275+
cancel()
2276+
2277+
mockHelper.AssertExpectations(t)
2278+
mockHandler.AssertExpectations(t)
2279+
}

0 commit comments

Comments
 (0)