Skip to content
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

accounts + main: Allow new accounts with 0 balance #718

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions accounts/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,10 @@ func TestAccountService(t *testing.T) {
acct := &OffChainBalanceAccount{
ID: testID,
Type: TypeInitialBalance,
CurrentBalance: 1234,
CurrentBalance: 0,
Invoices: AccountInvoices{
testHash: {},
testHash: {},
testHash2: {},
},
Payments: make(AccountPayments),
}
Expand All @@ -589,7 +590,7 @@ func TestAccountService(t *testing.T) {
AddIndex: 12,
SettleIndex: 12,
Hash: testHash,
AmountPaid: 777,
AmountPaid: 1000,
State: invpkg.ContractSettled,
}

Expand All @@ -598,7 +599,25 @@ func TestAccountService(t *testing.T) {
acct, err := s.store.Account(testID)
require.NoError(t, err)

return acct.CurrentBalance == (1234 + 777)
return acct.CurrentBalance == 1000
})

// Then settle a second invoice.
lnd.invoiceChan <- &lndclient.Invoice{
AddIndex: 13,
SettleIndex: 13,
Hash: testHash2,
AmountPaid: 777,
State: invpkg.ContractSettled,
}

// Ensure that the balance now adds up to the sum of
// both invoices.
assertEventually(t, func() bool {
acct, err := s.store.Account(testID)
require.NoError(t, err)

return acct.CurrentBalance == (1000 + 777)
})
},
}, {
Expand Down
4 changes: 0 additions & 4 deletions accounts/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ func (s *BoltStore) NewAccount(balance lnwire.MilliSatoshi,
expirationDate time.Time, label string) (*OffChainBalanceAccount,
error) {

if balance == 0 {
return nil, fmt.Errorf("a new account cannot have balance of 0")
}

// If a label is set, it must be unique, as we use it to identify the
// account in some of the RPCs. It also can't be mistaken for a hex
// encoded account ID to avoid confusion and make it easier for the CLI
Expand Down
7 changes: 1 addition & 6 deletions accounts/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ func TestAccountStore(t *testing.T) {
store, err := NewBoltStore(t.TempDir(), DBFilename)
require.NoError(t, err)

// An initial balance of 0 is not allowed, but later we can reach a
// zero balance.
_, err = store.NewAccount(0, time.Time{}, "")
require.ErrorContains(t, err, "cannot have balance of 0")

// Create an account that does not expire.
acct1, err := store.NewAccount(123, time.Time{}, "foo")
acct1, err := store.NewAccount(0, time.Time{}, "foo")
require.NoError(t, err)
require.False(t, acct1.HasExpired())

Expand Down
4 changes: 0 additions & 4 deletions cmd/litcli/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ func createAccount(ctx *cli.Context) error {
args = args.Tail()
}

if initialBalance <= 0 {
return fmt.Errorf("initial balance cannot be smaller than 1")
}

req := &litrpc.CreateAccountRequest{
AccountBalance: initialBalance,
ExpirationDate: expirationDate,
Expand Down
Loading