Skip to content

Commit 44ba94e

Browse files
authored
Merge pull request #527 from sputn1ck/github_actions
ci: add github actions
2 parents 446f163 + 4803941 commit 44ba94e

19 files changed

+158
-53
lines changed

.github/workflows/main.yml

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "*"
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
env:
16+
# go needs absolute directories, using the $HOME variable doesn't work here.
17+
GOCACHE: /home/runner/work/go/pkg/build
18+
GOPATH: /home/runner/work/go
19+
GO111MODULE: on
20+
21+
# If you change this value, please change it in the following files as well:
22+
# /Dockerfile
23+
GO_VERSION: 1.17
24+
25+
jobs:
26+
########################
27+
# RPC compile and check
28+
########################
29+
rpc-check:
30+
name: RPC compilation check
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: git checkout
34+
uses: actions/checkout@v2
35+
36+
- name: setup go ${{ env.GO_VERSION }}
37+
uses: actions/setup-go@v2
38+
with:
39+
go-version: '~${{ env.GO_VERSION }}'
40+
41+
- name: RPC for JS compilation
42+
run: make rpc-js-compile
43+
44+
- name: run check
45+
run: make rpc-check
46+
47+
########################
48+
# go mod check
49+
########################
50+
mod-check:
51+
name: go mod check
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: git checkout
55+
uses: actions/checkout@v2
56+
57+
- name: setup go ${{ env.GO_VERSION }}
58+
uses: actions/setup-go@v2
59+
with:
60+
go-version: '~${{ env.GO_VERSION }}'
61+
62+
- name: run check
63+
run: make mod-check
64+
65+
########################
66+
# build and lint code
67+
########################
68+
lint:
69+
name: build and lint code
70+
runs-on: ubuntu-latest
71+
steps:
72+
- name: git checkout
73+
uses: actions/checkout@v2
74+
with:
75+
fetch-depth: 0
76+
77+
- name: go cache
78+
uses: actions/cache@v1
79+
with:
80+
path: /home/runner/work/go
81+
key: lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
82+
restore-keys: |
83+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
84+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
85+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-
86+
loop-${{ runner.os }}-go-
87+
88+
- name: setup go ${{ env.GO_VERSION }}
89+
uses: actions/setup-go@v2
90+
with:
91+
go-version: '~${{ env.GO_VERSION }}'
92+
93+
- name: build
94+
run: make build tags=dev
95+
96+
- name: lint
97+
run: make lint
98+
99+
########################
100+
# run unit tests
101+
########################
102+
unit-test:
103+
name: run unit tests
104+
runs-on: ubuntu-latest
105+
steps:
106+
- name: git checkout
107+
uses: actions/checkout@v2
108+
109+
- name: go cache
110+
uses: actions/cache@v1
111+
with:
112+
path: /home/runner/work/go
113+
key: lnd-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
114+
restore-keys: |
115+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
116+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
117+
loop-${{ runner.os }}-go-${{ env.GO_VERSION }}-
118+
loop-${{ runner.os }}-go-
119+
120+
- name: setup go ${{ env.GO_VERSION }}
121+
uses: actions/setup-go@v2
122+
with:
123+
go-version: '~${{ env.GO_VERSION }}'
124+
125+
- name: run unit tests
126+
run: make unit

.golangci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ linters:
106106
- nilnil
107107
- stylecheck
108108
- thelper
109-
109+
- revive
110+
110111
# Additions compared to LND
111112
- exhaustruct
112113

@@ -120,6 +121,7 @@ issues:
120121
- path: _test\.go
121122
linters:
122123
- forbidigo
124+
- unparam
123125

124126
# Allow fmt.Printf() in loopd
125127
- path: cmd/loopd/*

client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ func (s *Client) resumeSwaps(ctx context.Context,
355355
if pend.State().State.Type() != loopdb.StateTypePending {
356356
continue
357357
}
358-
swap, err := resumeLoopOutSwap(ctx, swapCfg, pend)
358+
swap, err := resumeLoopOutSwap(swapCfg, pend)
359359
if err != nil {
360360
log.Errorf("resuming loop out swap: %v", err)
361361
continue

client_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func TestLoopOutFailWrongAmount(t *testing.T) {
141141
m.prepayInvoiceAmt += 10
142142
}, ErrPrepayAmountTooHigh)
143143
})
144-
145144
}
146145

147146
// TestLoopOutResume tests that swaps in various states are properly resumed

cmd/loop/loopin.go

-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func loopIn(ctx *cli.Context) error {
9494
amtStr = ctx.String("amt")
9595
case ctx.NArg() > 0:
9696
amtStr = args[0]
97-
args = args.Tail()
9897
default:
9998
// Show command help if no arguments and flags were provided.
10099
return cli.ShowCommandHelp(ctx, "in")

executor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type executorConfig struct {
3838

3939
// executor is responsible for executing swaps.
4040
//
41-
// TODO(roasbeef): rename to SubSwapper
41+
// TODO(roasbeef): rename to SubSwapper.
4242
type executor struct {
4343
wg sync.WaitGroup
4444
newSwaps chan genericSwap
@@ -134,9 +134,9 @@ func (s *executor) run(mainCtx context.Context,
134134

135135
swapDoneChan := make(chan int)
136136
nextSwapID := 0
137+
137138
for {
138139
select {
139-
140140
case newSwap := <-s.newSwaps:
141141
queue := queue.NewConcurrentQueue(10)
142142
queue.Start()

interface.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ type SwapInfo struct {
363363
OutgoingChanSet loopdb.ChannelSet
364364
}
365365

366-
// LastUpdate returns the last update time of the swap
366+
// LastUpdate returns the last update time of the swap.
367367
func (s *In) LastUpdate() time.Time {
368368
return s.LastUpdateTime
369369
}

loopdb/loop.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type SwapContract struct {
5858
ProtocolVersion ProtocolVersion
5959
}
6060

61-
// Loop contains fields shared between LoopIn and LoopOut
61+
// Loop contains fields shared between LoopIn and LoopOut.
6262
type Loop struct {
6363
Hash lntypes.Hash
6464
Events []*LoopEvent

loopdb/meta.go

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ func syncVersions(db *bbolt.DB, chainParams *chaincfg.Params) error {
9292
"db_version=%v", latestDBVersion, currentVersion)
9393

9494
switch {
95-
9695
// If the database reports a higher version that we are aware of, the
9796
// user is probably trying to revert to a prior version of lnd. We fail
9897
// here to prevent reversions and unintended corruption.

loopin.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
221221

222222
// Validate the response parameters the prevent us continuing with a
223223
// swap that is based on parameters outside our allowed range.
224-
err = validateLoopInContract(cfg.lnd, currentHeight, request, swapResp)
224+
err = validateLoopInContract(currentHeight, swapResp)
225225
if err != nil {
226226
return nil, err
227227
}
@@ -387,11 +387,7 @@ func resumeLoopInSwap(_ context.Context, cfg *swapConfig,
387387

388388
// validateLoopInContract validates the contract parameters against our
389389
// request.
390-
func validateLoopInContract(lnd *lndclient.LndServices,
391-
height int32,
392-
request *LoopInRequest,
393-
response *newLoopInResponse) error {
394-
390+
func validateLoopInContract(height int32, response *newLoopInResponse) error {
395391
// Verify that we are not forced to publish an htlc that locks up our
396392
// funds for too long in case the server doesn't follow through.
397393
if response.expiry-height > MaxLoopInAcceptDelta {
@@ -640,7 +636,6 @@ func (s *loopInSwap) waitForHtlcConf(globalCtx context.Context) (
640636
var conf *chainntnfs.TxConfirmation
641637
for conf == nil {
642638
select {
643-
644639
// P2WSH htlc confirmed.
645640
case conf = <-confChanP2WSH:
646641
s.htlc = s.htlcP2WSH
@@ -756,7 +751,6 @@ func (s *loopInSwap) publishOnChainHtlc(ctx context.Context) (bool, error) {
756751
}
757752

758753
return true, nil
759-
760754
}
761755

762756
// getTxFee calculates our fee for a transaction that we have broadcast. We use
@@ -875,7 +869,6 @@ func (s *loopInSwap) waitForSwapComplete(ctx context.Context,
875869
update.State)
876870

877871
switch update.State {
878-
879872
// Swap invoice was paid, so update server cost balance.
880873
case channeldb.ContractSettled:
881874
s.cost.Server -= update.AmtPaid

loopout.go

+6-9
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type executeConfig struct {
9292
sweeper *sweep.Sweeper
9393
statusChan chan<- SwapInfo
9494
blockEpochChan <-chan interface{}
95-
timerFactory func(d time.Duration) <-chan time.Time
95+
timerFactory func(time.Duration) <-chan time.Time
9696
loopOutMaxParts uint32
9797
totalPaymentTimout time.Duration
9898
maxPaymentRetries int
@@ -144,7 +144,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
144144
}
145145

146146
err = validateLoopOutContract(
147-
cfg.lnd, currentHeight, request, swapHash, swapResp,
147+
cfg.lnd, request, swapHash, swapResp,
148148
)
149149
if err != nil {
150150
return nil, err
@@ -246,8 +246,8 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
246246

247247
// resumeLoopOutSwap returns a swap object representing a pending swap that has
248248
// been restored from the database.
249-
func resumeLoopOutSwap(reqContext context.Context, cfg *swapConfig,
250-
pend *loopdb.LoopOut) (*loopOutSwap, error) {
249+
func resumeLoopOutSwap(cfg *swapConfig, pend *loopdb.LoopOut,
250+
) (*loopOutSwap, error) {
251251

252252
hash := lntypes.Hash(sha256.Sum256(pend.Contract.Preimage[:]))
253253

@@ -386,7 +386,6 @@ func (s *loopOutSwap) execute(mainCtx context.Context,
386386
// executeAndFinalize executes a swap and awaits the definitive outcome of the
387387
// offchain payments. When this method returns, the swap outcome is final.
388388
func (s *loopOutSwap) executeAndFinalize(globalCtx context.Context) error {
389-
390389
// Announce swap by sending out an initial update.
391390
err := s.sendUpdate(globalCtx)
392391
if err != nil {
@@ -996,7 +995,6 @@ func (s *loopOutSwap) waitForConfirmedHtlc(globalCtx context.Context) (
996995
}
997996

998997
s.log.Infof("Swap script confirmed on chain")
999-
1000998
} else {
1001999
s.log.Infof("Retrieving htlc onchain")
10021000
select {
@@ -1650,9 +1648,8 @@ func (s *loopOutSwap) sweep(ctx context.Context, htlcOutpoint wire.OutPoint,
16501648

16511649
// validateLoopOutContract validates the contract parameters against our
16521650
// request.
1653-
func validateLoopOutContract(lnd *lndclient.LndServices,
1654-
height int32, request *OutRequest, swapHash lntypes.Hash,
1655-
response *newLoopOutResponse) error {
1651+
func validateLoopOutContract(lnd *lndclient.LndServices, request *OutRequest,
1652+
swapHash lntypes.Hash, response *newLoopOutResponse) error {
16561653

16571654
// Check invoice amounts.
16581655
chainParams := lnd.ChainParams

loopout_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ func testLateHtlcPublish(t *testing.T) {
219219
ctx.AssertRegisterConf(false, defaultConfirmations)
220220

221221
// // Wait too long before publishing htlc.
222-
blockEpochChan <- int32(swap.CltvExpiry - 10)
222+
blockEpochChan <- swap.CltvExpiry - 10
223223

224224
signalSwapPaymentResult(
225225
errors.New(lndclient.PaymentResultUnknownPaymentHash),
@@ -430,7 +430,7 @@ func testCustomSweepConfTarget(t *testing.T) {
430430
// confirmation target.
431431
defaultConfTargetHeight := ctx.Lnd.Height +
432432
testLoopOutMinOnChainCltvDelta - DefaultSweepConfTargetDelta
433-
blockEpochChan <- int32(defaultConfTargetHeight)
433+
blockEpochChan <- defaultConfTargetHeight
434434
expiryChan <- time.Now()
435435

436436
// Expect another signing request.

store_mock_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,6 @@ func (s *storeMock) assertLoopInState(
246246
}
247247

248248
func (s *storeMock) assertStorePreimageReveal() {
249-
250249
s.t.Helper()
251250

252251
select {

swap.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
type swapKit struct {
1515
hash lntypes.Hash
1616

17-
height int32
17+
height int32 //nolint:structcheck
1818

1919
log *swap.PrefixLog
2020

swap/htlc.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
type HtlcOutputType uint8
2323

2424
const (
25-
// HtlcP2WSH is a pay-to-witness-script-hash output (segwit only)
25+
// HtlcP2WSH is a pay-to-witness-script-hash output (segwit only).
2626
HtlcP2WSH HtlcOutputType = iota
2727

2828
// HtlcP2TR is a pay-to-taproot output with three separate spend paths.
@@ -329,11 +329,15 @@ type HtlcScriptV2 struct {
329329
// newHTLCScriptV2 construct an HtlcScipt with the HTLC V2 witness script.
330330
//
331331
// <receiverHtlcKey> OP_CHECKSIG OP_NOTIF
332-
// OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY
333-
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY
332+
//
333+
// OP_DUP OP_HASH160 <HASH160(senderHtlcKey)> OP_EQUALVERIFY OP_CHECKSIGVERIFY
334+
// <cltv timeout> OP_CHECKLOCKTIMEVERIFY
335+
//
334336
// OP_ELSE
335-
// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1
336-
// OP_CHECKSEQUENCEVERIFY
337+
//
338+
// OP_SIZE <20> OP_EQUALVERIFY OP_HASH160 <ripemd(swapHash)> OP_EQUALVERIFY 1
339+
// OP_CHECKSEQUENCEVERIFY
340+
//
337341
// OP_ENDIF .
338342
func newHTLCScriptV2(cltvExpiry int32, senderHtlcKey,
339343
receiverHtlcKey [33]byte, swapHash lntypes.Hash) (*HtlcScriptV2, error) {

test/context.go

-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func (ctx *Context) NotifySpend(tx *wire.MsgTx, inputIndex uint32) {
6262
}:
6363
case <-time.After(Timeout):
6464
ctx.T.Fatalf("htlc spend not consumed")
65-
6665
}
6766
}
6867

@@ -76,7 +75,6 @@ func (ctx *Context) NotifyConf(tx *wire.MsgTx) {
7675
}:
7776
case <-time.After(Timeout):
7877
ctx.T.Fatalf("htlc spend not consumed")
79-
8078
}
8179
}
8280

0 commit comments

Comments
 (0)