Skip to content

Commit 2328dd9

Browse files
author
Mikhail Kornilov
authored
Release: [DFI-594] VM retry (#186)
* [DFI-575] LCS viewer (#182) * [DFI-575] VM mod: LCS viewer prototype added * [DFI-575] CLI output fix * [DFI-575] CLI output fix * [DFI-575] ModulePath support added * [DFI-575] Docs added * [DFI-575] REST API added + REST test; Cosmos SDK Swagger dependency fix * [DFI-594] vm mod: retry mechanism refactoring (option to disable request timeout) * [DFI-594] Linter fix * [DFI-594] Sleep added (useful for tests only)
1 parent 9370b89 commit 2328dd9

File tree

16 files changed

+456
-185
lines changed

16 files changed

+456
-185
lines changed

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ func NewDnServiceApp(logger log.Logger, db dbm.DB, config *config.VMConfig, invC
263263
)
264264

265265
// Upgrade handler with name matching proposal name should be registered here.
266-
//app.upgradeKeeper.SetUpgradeHandler("My_update", func(ctx sdk.Context, plan upgrade.Plan) { })
266+
app.upgradeKeeper.SetUpgradeHandler("v0.6.1", func(ctx sdk.Context, plan upgrade.Plan) {})
267267

268268
// VMKeeper stores VM resources and interacts with DVM.
269269
app.vmKeeper = vm.NewKeeper(

app/common_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,10 @@ func NewTestDnAppDVM(t *testing.T, logOpts ...log.Option) (*DnServiceApp, string
236236

237237
// create VM config
238238
config := &vmConfig.VMConfig{
239-
Address: dvmAddr,
240-
DataListen: dsAddr,
241-
MaxAttempts: 10,
242-
InitialBackoff: 500,
243-
MaxBackoff: 1500,
244-
BackoffMultiplier: 0.1,
239+
Address: dvmAddr,
240+
DataListen: dsAddr,
241+
MaxAttempts: 10,
242+
ReqTimeoutInMs: 1000,
245243
}
246244

247245
// create app

app/integ_gov_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func TestIntegGov_StdlibUpdate(t *testing.T) {
6363
t,
6464
true,
6565
cliTester.DaemonLogLevelOption("x/vm/dsserver:info,x/vm:info,x/gov:info,main:info,state:info,*:error"),
66-
cliTester.VMCommunicationOption(50, 1000, 100),
66+
cliTester.VMCommunicationOption(5, 1000),
6767
cliTester.VMCommunicationBaseAddressNetOption("tcp://127.0.0.1"),
6868
)
6969
defer ct.Close()

app/integ_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func TestIntegVM_CommunicationUDSOverDocker(t *testing.T) {
3535
ct := cliTester.New(
3636
t,
3737
false,
38-
cliTester.VMCommunicationOption(50, 1000, 100),
38+
cliTester.VMCommunicationOption(5, 1000),
3939
cliTester.VMCommunicationBaseAddressUDSOption(dsSocket, dvmSocket),
4040
)
4141
defer ct.Close()

app/integ_test.go

Lines changed: 8 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
package app
44

55
import (
6-
"context"
76
"encoding/hex"
87
"io/ioutil"
9-
"net"
108
"os"
119
"path"
1210
"strings"
@@ -15,75 +13,17 @@ import (
1513
"time"
1614

1715
"github.com/cosmos/cosmos-sdk/server"
18-
"github.com/dfinance/dvm-proto/go/vm_grpc"
1916
"github.com/stretchr/testify/require"
20-
"google.golang.org/grpc"
21-
"google.golang.org/grpc/codes"
22-
grpcStatus "google.golang.org/grpc/status"
2317

2418
"github.com/dfinance/dnode/helpers"
2519
"github.com/dfinance/dnode/helpers/tests"
2620
cliTester "github.com/dfinance/dnode/helpers/tests/clitester"
21+
"github.com/dfinance/dnode/helpers/tests/mockdvm"
2722
testUtils "github.com/dfinance/dnode/helpers/tests/utils"
2823
"github.com/dfinance/dnode/x/vm"
2924
"github.com/dfinance/dnode/x/vm/client/vm_client"
3025
)
3126

32-
type MockDVM struct {
33-
server *grpc.Server
34-
failExecution bool
35-
failResponse bool
36-
execDelay time.Duration
37-
}
38-
39-
func (s *MockDVM) SetExecutionFail() { s.failExecution = true }
40-
func (s *MockDVM) SetExecutionOK() { s.failExecution = false }
41-
func (s *MockDVM) SetResponseFail() { s.failResponse = true }
42-
func (s *MockDVM) SetResponseOK() { s.failResponse = false }
43-
func (s *MockDVM) SetExecutionDelay(dur time.Duration) {
44-
s.execDelay = dur
45-
}
46-
func (s *MockDVM) Stop() {
47-
if s.server != nil {
48-
s.server.Stop()
49-
}
50-
}
51-
52-
func (s *MockDVM) PublishModule(ctx context.Context, in *vm_grpc.VMPublishModule) (*vm_grpc.VMExecuteResponse, error) {
53-
if s.failExecution {
54-
return nil, grpcStatus.Errorf(codes.Internal, "failing gRPC execution")
55-
}
56-
57-
resp := &vm_grpc.VMExecuteResponse{}
58-
if !s.failResponse {
59-
resp = &vm_grpc.VMExecuteResponse{
60-
WriteSet: nil,
61-
Events: nil,
62-
GasUsed: 1,
63-
Status: vm_grpc.ContractStatus_Discard,
64-
StatusStruct: nil,
65-
}
66-
}
67-
68-
return resp, nil
69-
}
70-
71-
func StartMockDVMService(listener net.Listener) *MockDVM {
72-
s := &MockDVM{
73-
execDelay: 100 * time.Millisecond,
74-
}
75-
76-
server := grpc.NewServer()
77-
vm_grpc.RegisterVMModulePublisherServer(server, s)
78-
79-
go func() {
80-
server.Serve(listener)
81-
}()
82-
s.server = server
83-
84-
return s
85-
}
86-
8727
// Test dnode crash on VM Tx failure
8828
func TestInteg_ConsensusFailure(t *testing.T) {
8929
const script = `
@@ -167,7 +107,7 @@ func TestIntegVM_ExecuteScriptViaCLI(t *testing.T) {
167107
ct := cliTester.New(
168108
t,
169109
false,
170-
cliTester.VMCommunicationOption(50, 1000, 100),
110+
cliTester.VMCommunicationOption(5, 1000),
171111
cliTester.VMCommunicationBaseAddressNetOption("tcp://127.0.0.1"),
172112
)
173113
defer ct.Close()
@@ -254,7 +194,7 @@ func TestIntegVM_ExecuteScriptViaREST(t *testing.T) {
254194
ct := cliTester.New(
255195
t,
256196
false,
257-
cliTester.VMCommunicationOption(50, 1000, 100),
197+
cliTester.VMCommunicationOption(5, 1000),
258198
cliTester.VMCommunicationBaseAddressNetOption("tcp://127.0.0.1"),
259199
)
260200
defer ct.Close()
@@ -358,7 +298,7 @@ func TestIntegVM_DeployModuleViaCLI(t *testing.T) {
358298
ct := cliTester.New(
359299
t,
360300
false,
361-
cliTester.VMCommunicationOption(50, 1000, 100),
301+
cliTester.VMCommunicationOption(5, 1000),
362302
cliTester.VMCommunicationBaseAddressNetOption("tcp://127.0.0.1"),
363303
)
364304
defer ct.Close()
@@ -417,7 +357,7 @@ func TestIntegVM_DeployModuleViaREST(t *testing.T) {
417357
ct := cliTester.New(
418358
t,
419359
false,
420-
cliTester.VMCommunicationOption(50, 1000, 100),
360+
cliTester.VMCommunicationOption(5, 1000),
421361
cliTester.VMCommunicationBaseAddressNetOption("tcp://127.0.0.1"),
422362
)
423363
defer ct.Close()
@@ -486,7 +426,7 @@ func TestIntegVM_RequestRetry(t *testing.T) {
486426
ct := cliTester.New(
487427
t,
488428
true,
489-
cliTester.VMCommunicationOption(100, 500, 10),
429+
cliTester.VMCommunicationOption(5, 100),
490430
cliTester.VMCommunicationBaseAddressUDSOption(dsSocket, mockDVMSocket),
491431
)
492432
defer ct.Close()
@@ -496,7 +436,7 @@ func TestIntegVM_RequestRetry(t *testing.T) {
496436
mockDVMListener, err := helpers.GetGRpcNetListener("unix://" + mockDVMSocketPath)
497437
require.NoError(t, err, "creating MockDVM listener")
498438

499-
mockDvm := StartMockDVMService(mockDVMListener)
439+
mockDvm := mockdvm.StartMockDVMService(mockDVMListener)
500440
defer mockDvm.Stop()
501441
require.NoError(t, testUtils.WaitForFileExists(mockDVMSocketPath, 1*time.Second), "MockDVM start failed")
502442

@@ -580,7 +520,7 @@ func TestIntegVM_CommunicationUDS(t *testing.T) {
580520
ct := cliTester.New(
581521
t,
582522
false,
583-
cliTester.VMCommunicationOption(50, 1000, 100),
523+
cliTester.VMCommunicationOption(5, 1000),
584524
cliTester.VMCommunicationBaseAddressUDSOption(dsSocket, dvmSocket),
585525
)
586526
defer ct.Close()

cmd/config/config.go

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ const (
3131
DefaultDataListen = "tcp://127.0.0.1:50052" // Default data server address to listen for connections from VM.
3232

3333
// Default retry configs.
34-
DefaultMaxAttempts = 0 // Default VM retry attempts.
35-
DefaultInitialBackoff = 1000 // Default VM 100 milliseconds for retry attempts.
36-
DefaultMaxBackoff = 2000 // Default VM max backoff.
37-
DefaultBackoffMultiplier = 0.1 // Default backoff multiplayer (10)
34+
DefaultMaxAttempts = 0 // Default maximum attempts for retry.
35+
DefaultReqTimeout = 0 // Default request timeout per attempt [ms].
3836

3937
// Default governance params.
4038
DefaultGovMinDepositAmount = "100000000000000000000" // 100 dfi
@@ -52,23 +50,18 @@ type VMConfig struct {
5250
Address string `mapstructure:"vm_address"` // address of virtual machine.
5351
DataListen string `mapstructure:"vm_data_listen"` // data listen.
5452

55-
// Retry policy.
56-
// Example how backoff works - https://stackoverflow.com/questions/43224683/what-does-backoffmultiplier-mean-in-defaultretrypolicy.
57-
MaxAttempts int `mapstructure:"vm_retry_max_attempts"` // maximum attempts for retry, for infinity retry - use 0.
58-
InitialBackoff int `mapstructure:"vm_retry_initial_backoff"` // initial back off in ms.
59-
MaxBackoff int `mapstructure:"vm_retry_max_backoff"` // max backoff in ms.
60-
BackoffMultiplier float64 `mapstructure:"vm_retry_backoff_multiplier"` // backoff multiplier.
53+
// Retry policy
54+
MaxAttempts uint `mapstructure:"vm_retry_max_attempts"` // maximum attempts for retry (0 - infinity)
55+
ReqTimeoutInMs uint `mapstructure:"vm_retry_req_timeout_ms"` // request timeout per attempt (0 - infinity) [ms]
6156
}
6257

6358
// Default VM configuration.
6459
func DefaultVMConfig() *VMConfig {
6560
return &VMConfig{
66-
Address: DefaultVMAddress,
67-
DataListen: DefaultDataListen,
68-
MaxAttempts: DefaultMaxAttempts,
69-
InitialBackoff: DefaultInitialBackoff,
70-
MaxBackoff: DefaultMaxBackoff,
71-
BackoffMultiplier: DefaultBackoffMultiplier,
61+
Address: DefaultVMAddress,
62+
DataListen: DefaultDataListen,
63+
MaxAttempts: DefaultMaxAttempts,
64+
ReqTimeoutInMs: DefaultReqTimeout,
7265
}
7366
}
7467

cmd/config/vm_config_template.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,10 @@ vm_data_listen = "{{ .DataListen }}"
2929
# VM retry settings.
3030
3131
## Retry max attempts.
32-
## Default is 0 - infinity attempts, -1 - to disable.
32+
## Default is 0 - infinity attempts.
3333
vm_retry_max_attempts = {{ .MaxAttempts }}
3434
35-
## Initial backoff in ms.
36-
## Default is 100ms.
37-
vm_retry_initial_backoff = {{ .InitialBackoff }}
38-
39-
## Max backoff in ms.
40-
## Default is 150ms.
41-
vm_retry_max_backoff = {{ .MaxBackoff }}
42-
43-
## Backoff multiplier.
44-
## Default is 0.1
45-
vm_retry_backoff_multiplier = {{ .BackoffMultiplier }}
35+
## Request timeout per attempt in ms.
36+
## Default is 0 - infinite (no timeout).
37+
vm_retry_req_timeout_ms = {{ .ReqTimeoutInMs }}
4638
`

0 commit comments

Comments
 (0)