From 1f50c7839ab3651c8fe0575be6341dea220891d5 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 21 Dec 2021 14:32:56 +0100 Subject: [PATCH] server+auctioneer: make batch version configurable --- auctioneer/account_subscription.go | 17 ++++++----- auctioneer/account_subscription_test.go | 39 ++++++++++++++----------- auctioneer/client.go | 17 +++++++---- server.go | 3 ++ 4 files changed, 45 insertions(+), 31 deletions(-) diff --git a/auctioneer/account_subscription.go b/auctioneer/account_subscription.go index 1478ea2..affaa1f 100644 --- a/auctioneer/account_subscription.go +++ b/auctioneer/account_subscription.go @@ -16,13 +16,14 @@ import ( // auction. It can also perform the 3-way authentication handshake that is // needed to authenticate a trader for a subscription. type acctSubscription struct { - acctKey *keychain.KeyDescriptor - commitHash [32]byte - sendMsg func(*auctioneerrpc.ClientAuctionMessage) error - signer lndclient.SignerClient - msgChan chan *auctioneerrpc.ServerAuctionMessage - errChan chan error - quit chan struct{} + acctKey *keychain.KeyDescriptor + commitHash [32]byte + sendMsg func(*auctioneerrpc.ClientAuctionMessage) error + signer lndclient.SignerClient + msgChan chan *auctioneerrpc.ServerAuctionMessage + batchVersion order.BatchVersion + errChan chan error + quit chan struct{} } // authenticate performs the 3-way authentication handshake between the trader @@ -50,7 +51,7 @@ func (s *acctSubscription) authenticate(ctx context.Context) error { Msg: &auctioneerrpc.ClientAuctionMessage_Commit{ Commit: &auctioneerrpc.AccountCommitment{ CommitHash: s.commitHash[:], - BatchVersion: uint32(order.CurrentBatchVersion), + BatchVersion: uint32(s.batchVersion), }, }, }) diff --git a/auctioneer/account_subscription_test.go b/auctioneer/account_subscription_test.go index ed8cfb0..271a876 100644 --- a/auctioneer/account_subscription_test.go +++ b/auctioneer/account_subscription_test.go @@ -12,6 +12,7 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/lightninglabs/pool/auctioneerrpc" "github.com/lightninglabs/pool/internal/test" + "github.com/lightninglabs/pool/order" "github.com/lightningnetwork/lnd/keychain" ) @@ -40,10 +41,11 @@ func TestAccountSubscriptionAuthenticate(t *testing.T) { return nil } sub = &acctSubscription{ - acctKey: testAccountDesc, - sendMsg: sendMsg, - signer: testSigner, - msgChan: srvMsgChan, + acctKey: testAccountDesc, + sendMsg: sendMsg, + signer: testSigner, + msgChan: srvMsgChan, + batchVersion: order.CurrentBatchVersion, } ) @@ -102,10 +104,11 @@ func TestAccountSubscriptionAuthenticateAbort(t *testing.T) { return nil } sub = &acctSubscription{ - acctKey: testAccountDesc, - sendMsg: sendMsg, - signer: testSigner, - msgChan: srvMsgChan, + acctKey: testAccountDesc, + sendMsg: sendMsg, + signer: testSigner, + msgChan: srvMsgChan, + batchVersion: order.CurrentBatchVersion, } ) @@ -154,10 +157,11 @@ func TestAccountSubscriptionAuthenticateContextClose(t *testing.T) { return nil } sub = &acctSubscription{ - acctKey: testAccountDesc, - sendMsg: sendMsg, - signer: testSigner, - msgChan: srvMsgChan, + acctKey: testAccountDesc, + sendMsg: sendMsg, + signer: testSigner, + msgChan: srvMsgChan, + batchVersion: order.CurrentBatchVersion, } ctxc, cancel = context.WithCancel(context.Background()) ) @@ -208,11 +212,12 @@ func TestAccountSubscriptionAuthenticateError(t *testing.T) { return nil } sub = &acctSubscription{ - acctKey: testAccountDesc, - sendMsg: sendMsg, - signer: testSigner, - msgChan: srvMsgChan, - errChan: make(chan error), + acctKey: testAccountDesc, + sendMsg: sendMsg, + signer: testSigner, + msgChan: srvMsgChan, + batchVersion: order.CurrentBatchVersion, + errChan: make(chan error), } ) diff --git a/auctioneer/client.go b/auctioneer/client.go index c0b3e4a..78d3b67 100644 --- a/auctioneer/client.go +++ b/auctioneer/client.go @@ -105,6 +105,10 @@ type Config struct { // trader's pending batch. BatchCleaner BatchCleaner + // BatchVersion is the batch version that we should use when + // authenticating with the auction server. + BatchVersion order.BatchVersion + // GenUserAgent is a function that generates a complete user agent // string given the incoming request context. GenUserAgent func(context.Context) string @@ -581,12 +585,13 @@ func (c *Client) connectAndAuthenticate(ctx context.Context, // Before we can expect to receive any updates, we need to perform the // 3-way authentication handshake. sub = &acctSubscription{ - acctKey: acctKey, - sendMsg: c.SendAuctionMessage, - signer: c.cfg.Signer, - msgChan: make(chan *auctioneerrpc.ServerAuctionMessage), - errChan: tempErrChan, - quit: make(chan struct{}), + acctKey: acctKey, + sendMsg: c.SendAuctionMessage, + signer: c.cfg.Signer, + msgChan: make(chan *auctioneerrpc.ServerAuctionMessage), + batchVersion: c.cfg.BatchVersion, + errChan: tempErrChan, + quit: make(chan struct{}), } c.subscribedAcctsMtx.Lock() c.subscribedAccts[acctPubKey] = sub diff --git a/server.go b/server.go index b9ceabb..5f1a6db 100644 --- a/server.go +++ b/server.go @@ -505,6 +505,9 @@ func (s *Server) setupClient() error { MaxBackoff: s.cfg.MaxBackoff, BatchSource: s.db, BatchCleaner: s.fundingManager, + BatchVersion: order.BatchVersion( + s.cfg.DebugConfig.BatchVersion, + ), GenUserAgent: func(ctx context.Context) string { return UserAgent(InitiatorFromContext(ctx)) },