From e98c465f7b7fbbb30f451e2a288dc344efd0b6c8 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Mon, 5 Oct 2020 14:31:39 +0200 Subject: [PATCH] account: query auctioneer only if necessary In case the auctioneer is offline or restarting during the initial boot up of the trader server, we get a hard failure directly if we try to query the terms when the server connection isn't ready yet. This isn't really nice as we'd never come into the auto-retry of the account subscription that way. To optimize this, we only query the terms when we actually need them. This makes it possible for confirmed, open accounts to go into the subscription connection re-try logic. We'd only hard fail on startup if there are any pending accounts and the auctioneer is offline exactly during the trader boot up. --- account/manager.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/account/manager.go b/account/manager.go index 00a50ab..b521105 100644 --- a/account/manager.go +++ b/account/manager.go @@ -399,11 +399,6 @@ func (m *Manager) resumeAccount(ctx context.Context, account *Account, // nolint return fmt.Errorf("unable to construct account output: %v", err) } - terms, err := m.cfg.Auctioneer.Terms(ctx) - if err != nil { - return fmt.Errorf("could not query auctioneer terms: %v", err) - } - var accountTx *wire.MsgTx switch account.State { // In StateInitiated, we'll attempt to fund our account. @@ -534,6 +529,11 @@ func (m *Manager) resumeAccount(ctx context.Context, account *Account, // nolint if err != nil { return err } + terms, err := m.cfg.Auctioneer.Terms(ctx) + if err != nil { + return fmt.Errorf("could not query auctioneer terms: "+ + "%v", err) + } // Proceed to watch for the account on-chain. numConfs := NumConfsForValue( @@ -564,6 +564,15 @@ func (m *Manager) resumeAccount(ctx context.Context, account *Account, // nolint // and would therefore not be noticed by us. The account would stay // pending forever in that case. case StatePendingUpdate, StatePendingBatch: + // We need to know the maximum account value to scale the number + // of confirmations the same way the auctioneer does to avoid + // getting the state out of sync. + terms, err := m.cfg.Auctioneer.Terms(ctx) + if err != nil { + return fmt.Errorf("could not query auctioneer terms: "+ + "%v", err) + } + numConfs := NumConfsForValue( account.Value, terms.MaxAccountValue, )