Skip to content

Commit

Permalink
go 1.19 formatting and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
chappjc committed Aug 4, 2022
1 parent 66f5f9c commit 1ba196b
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 78 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,7 +18,7 @@ jobs:
- name: Check out source
uses: actions/checkout@v3
- name: Install Linters
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.46.1"
run: "curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.47.3"

- name: Test
env:
Expand Down
20 changes: 10 additions & 10 deletions client/comms/wsconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions client/core/simnet_trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 9 additions & 9 deletions client/core/trade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2819,10 +2819,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.
Expand Down
5 changes: 3 additions & 2 deletions client/db/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 8 additions & 8 deletions client/rpcserver/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions dex/calc/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dex/encode/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions dex/encode/passbytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] != '"' {
Expand Down
20 changes: 11 additions & 9 deletions dex/encode/passbytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion dex/networks/zec/addr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:]...)
Expand Down
2 changes: 1 addition & 1 deletion server/asset/dcr/live_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions server/book/orderpq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions server/db/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 9 additions & 8 deletions server/market/market.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
// 1. Receive and validate new order data (amounts vs. lot size, check fees,
// utxos, sufficient market buy buffer, etc.).
// 2. Put incoming orders into the current epoch queue.
// 3. Maintain an order book, which must also implement matcher.Booker.
// 4. Initiate order matching with matcher.Match(book, currentQueue)
// 5. 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
// 6. Cycle the epochs.
// 7. Record all events with the archivist.
type Market struct {
marketInfo *dex.MarketInfo

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1ba196b

Please sign in to comment.