From 367a67c3d70d53c1fa02080d6f49230374cfe2ae Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 8 Apr 2020 15:06:49 +0200 Subject: [PATCH] client+order: remove account from account tally --- order/batch_verifier.go | 16 +++++++++------- order/tradingfees.go | 4 ---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/order/batch_verifier.go b/order/batch_verifier.go index f937b97..9018338 100644 --- a/order/batch_verifier.go +++ b/order/batch_verifier.go @@ -83,7 +83,8 @@ func (v *batchVerifier) Verify(batch *Batch) error { // First go through all orders that were matched for us. We'll make sure // we know of the order and that the numbers check out on a high level. - accounts := make(map[[33]byte]*AccountTally) + tallies := make(map[[33]byte]*AccountTally) + accounts := make(map[[33]byte]*account.Account) for nonce, theirOrders := range batch.MatchedOrders { // Find our order in the database. ourOrder, err := v.orderStore.GetOrder(nonce) @@ -104,7 +105,7 @@ func (v *batchVerifier) Verify(batch *Batch) error { // Find the account the order spends from, if it isn't already // in the cache because another order spends from it. - tally, ok := accounts[acctKeyRaw] + tally, ok := tallies[acctKeyRaw] if !ok { acct, err := v.getAccount(acctKey) if err != nil { @@ -112,10 +113,10 @@ func (v *batchVerifier) Verify(batch *Batch) error { acctKeyRaw, err) } tally = &AccountTally{ - Account: acct, EndingBalance: acct.Value, } - accounts[acctKeyRaw] = tally + tallies[acctKeyRaw] = tally + accounts[acctKeyRaw] = acct } // Now that we know which of our orders were involved in the @@ -175,13 +176,14 @@ func (v *batchVerifier) Verify(batch *Batch) error { for _, diff := range batch.AccountDiffs { // We only should get diffs for accounts that have orders in the // batch. If not, something's messed up. - tally, ok := accounts[diff.AccountKeyRaw] + tally, ok := tallies[diff.AccountKeyRaw] if !ok { return &MismatchErr{ msg: fmt.Sprintf("got diff for uninvolved "+ "account %x", diff.AccountKeyRaw), } } + acct := accounts[diff.AccountKeyRaw] // Now that we know how many channels were created from the // given account, let's also account for the chain fees. @@ -198,7 +200,7 @@ func (v *batchVerifier) Verify(batch *Batch) error { } // Make sure the ending state of the account is correct. - err := diff.validateEndingState(batch.BatchTX, tally.Account) + err := diff.validateEndingState(batch.BatchTX, acct) if err != nil { return newMismatchErr( err, "account %x diff is incorrect", @@ -210,7 +212,7 @@ func (v *batchVerifier) Verify(batch *Batch) error { // output has been recreated (which means the expiry has been // reset as the CSV starts counting again in the new output). if diff.EndingState == clmrpc.AccountDiff_OUTPUT_RECREATED && - diff.Expiry != tally.Expiry { + diff.Expiry != acct.Expiry { return &MismatchErr{ msg: fmt.Sprintf("account %x has invalid "+ diff --git a/order/tradingfees.go b/order/tradingfees.go index 6a7f2ed..7a5ef4b 100644 --- a/order/tradingfees.go +++ b/order/tradingfees.go @@ -4,7 +4,6 @@ import ( "github.com/btcsuite/btcd/blockchain" "github.com/btcsuite/btcutil" "github.com/btcsuite/btcwallet/wallet/txrules" - "github.com/lightninglabs/agora/client/account" "github.com/lightninglabs/agora/client/clmscript" "github.com/lightningnetwork/lnd/input" "github.com/lightningnetwork/lnd/lnwallet/chainfee" @@ -152,9 +151,6 @@ func EstimateTraderFee(numTraderChans uint32, // AccountTally keeps track of an account's balance and fees for all orders in // a batch that spend from/use that account. type AccountTally struct { - // Account is the embedded account this tally is related to. - *account.Account - // EndingBalance is the ending balance for a trader's account. EndingBalance btcutil.Amount