Skip to content

Commit

Permalink
Merge pull request #681 from dashpay/backport-12-to-13
Browse files Browse the repository at this point in the history
chore: merge v0.12-dev into v0.13-dev
  • Loading branch information
lklimek authored Sep 13, 2023
2 parents 5edf552 + 0c9e744 commit a94c22e
Show file tree
Hide file tree
Showing 20 changed files with 465 additions and 114 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: "1.19"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand Down Expand Up @@ -55,7 +55,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: "1.19"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand All @@ -80,7 +80,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: "1.19"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ jobs:
with:
go-version: "1.19"

- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: "Check generated mocks"
run: |
set -euo pipefail
readonly MOCKERY=2.32.0 # N.B. no leading "v"
readonly MOCKERY=2.33.2 # N.B. no leading "v"
curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf -
make mockery 2>/dev/null
Expand All @@ -51,7 +51,7 @@ jobs:
with:
go-version: "1.19"

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1 # we need a .git directory to run git diff

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
inputs:
tag:
type: string
description: 'Docker tag'
description: "Docker tag"
required: false
release:
types:
Expand All @@ -17,7 +17,7 @@ jobs:
build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@master
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:
with:
result-encoding: string
script: |
if (github.ref_type == 'tag' && !contains(github.ref_name,'-dev')) {
if ('${{ github.ref_type }}' == 'tag' && ! '${{ github.ref_name }}'.includes('-dev')) {
return 'tenderdash,stable'
}
return 'tenderdash,dev,deadlock'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docs-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Install generator dependencies
run: |
apk add --no-cache make bash git npm
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
# We need to fetch full history so the backport branches for previous
# versions will be available for the build.
Expand All @@ -49,7 +49,7 @@ jobs:
permissions:
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
with:
name: build-output
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up Docker Buildx
uses: docker/[email protected]

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: technote-space/get-diff-action@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/jepsen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the Jepsen repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
repository: 'tendermint/jepsen'

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
CGO_LDFLAGS: "-L/usr/local/lib -ldashbls -lrelic_s -lmimalloc-secure -lgmp"
CGO_CXXFLAGS: "-I/usr/local/include"
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdown-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
markdown-link-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/markdown-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt-get update && sudo apt-get install -y libpcap-dev
- name: Lint Code Base
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: bufbuild/[email protected]
- uses: bufbuild/buf-lint-action@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/[email protected]
with:
go-version: "1.19"
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: technote-space/get-diff-action@v6
with:
PATTERNS: |
Expand Down
28 changes: 28 additions & 0 deletions dash/core/client.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//go:generate ../../scripts/mockery_generate.sh Client

package core

import (
"fmt"
"time"

"github.com/dashpay/dashd-go/btcjson"
rpc "github.com/dashpay/dashd-go/rpcclient"
Expand All @@ -13,6 +16,8 @@ import (

const ModuleName = "rpcclient"

var sleep = time.Sleep

// QuorumVerifier represents subset of priv validator features that
// allows verification of threshold signatures.
type QuorumVerifier interface {
Expand Down Expand Up @@ -220,3 +225,26 @@ func (rpcClient *RPCClient) QuorumVerify(
return resp, err

}

// WaitForMNReady waits until the masternode is ready
func WaitForMNReady(client Client, retryTimeout time.Duration) error {
for {
result, err := client.MasternodeStatus()
if err != nil {
return fmt.Errorf("failed to get masternode status: %w", err)
}
switch result.State {
case btcjson.MNStatusStateReady:
return nil
case btcjson.MNStatusStateWaitingForProtx:
sleep(retryTimeout)
case btcjson.MNStatusStatePoseBanned,
btcjson.MNStatusStateRemoved,
btcjson.MNStatusStateOperatorKeyChanged,
btcjson.MNStatusStateProtxIpChanged,
btcjson.MNStatusStateError,
btcjson.MNStatusStateUnknown:
return fmt.Errorf("unexpected masternode state %s", result.State)
}
}
}
94 changes: 94 additions & 0 deletions dash/core/client_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package core

import (
"errors"
"fmt"
"testing"
"time"

"github.com/dashpay/dashd-go/btcjson"
"github.com/stretchr/testify/require"

"github.com/dashpay/tenderdash/dash/core/mocks"
)

func TestWaitForMNReady(t *testing.T) {
retryTimeout := 1 * time.Millisecond
sleep = func(d time.Duration) {
require.Equal(t, d, retryTimeout)
}
defer func() { sleep = time.Sleep }()
testCases := []struct {
states []btcjson.MNStatusState
wantErr string
}{
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateReady},
},
{
states: []btcjson.MNStatusState{
btcjson.MNStatusStateWaitingForProtx,
btcjson.MNStatusStateReady,
},
},
{
states: []btcjson.MNStatusState{
btcjson.MNStatusStateWaitingForProtx,
btcjson.MNStatusStateWaitingForProtx,
btcjson.MNStatusStateWaitingForProtx,
btcjson.MNStatusStateReady,
},
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStatePoseBanned},
wantErr: string(btcjson.MNStatusStatePoseBanned),
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateRemoved},
wantErr: string(btcjson.MNStatusStateRemoved),
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateOperatorKeyChanged},
wantErr: string(btcjson.MNStatusStateOperatorKeyChanged),
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateProtxIpChanged},
wantErr: string(btcjson.MNStatusStateProtxIpChanged),
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateError},
wantErr: string(btcjson.MNStatusStateError),
},
{
states: []btcjson.MNStatusState{btcjson.MNStatusStateUnknown},
wantErr: string(btcjson.MNStatusStateUnknown),
},
}
for i, tc := range testCases {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
client := mocks.NewClient(t)
for _, state := range tc.states {
client.
On("MasternodeStatus").
Once().
Return(&btcjson.MasternodeStatusResult{State: state}, nil)
}
err := WaitForMNReady(client, 1*time.Millisecond)
if tc.wantErr != "" {
require.ErrorContains(t, err, tc.wantErr)
} else {
require.NoError(t, err)
}
})
}
}

func TestWaitForMNReadyError(t *testing.T) {
err := errors.New("some error")
client := mocks.NewClient(t)
client.
On("MasternodeStatus").
Once().
Return(nil, err)
require.ErrorContains(t, WaitForMNReady(client, 1), err.Error())
}
Loading

0 comments on commit a94c22e

Please sign in to comment.