From 022b3103eea41530494f5e24325bfd604596f152 Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:18:56 +0800 Subject: [PATCH 1/2] opt: remove disable-address-verify flag --- config/config.go | 3 --- integrate_test/mock_deamon.go | 2 +- main.go | 5 +---- walletevent/wallet_event.go | 18 +++++------------- walletevent/wallet_event_test.go | 4 +--- 5 files changed, 8 insertions(+), 24 deletions(-) diff --git a/config/config.go b/config/config.go index 2a6bddd..a2cb574 100644 --- a/config/config.go +++ b/config/config.go @@ -18,8 +18,6 @@ type Config struct { Metrics *metrics.MetricsConfig Trace *metrics.TraceConfig RateLimit *RateLimitCofnig - - DisableAddressVeirfication bool } type APIConfig struct { @@ -50,7 +48,6 @@ func DefaultConfig() *Config { cfg.Metrics.Exporter.Graphite.Port = 4569 cfg.Trace.ServerName = "venus-gateway" cfg.Trace.JaegerEndpoint = "" - cfg.DisableAddressVeirfication = false return cfg } diff --git a/integrate_test/mock_deamon.go b/integrate_test/mock_deamon.go index ecaf2aa..8dc8210 100644 --- a/integrate_test/mock_deamon.go +++ b/integrate_test/mock_deamon.go @@ -70,7 +70,7 @@ func MockMain(ctx context.Context, validateMiner []address.Address, repoPath str } authClient := mocks.NewMockAuthClient() authClient.AddMockUser(ctx, user...) - walletStream := walletevent.NewWalletEventStream(ctx, authClient, requestCfg, true) + walletStream := walletevent.NewWalletEventStream(ctx, authClient, requestCfg) proofStream := proofevent.NewProofEventStream(ctx, minerValidator, requestCfg) marketStream := marketevent.NewMarketEventStream(ctx, minerValidator, &types.RequestConfig{ diff --git a/main.go b/main.go index 7d66e12..197d908 100644 --- a/main.go +++ b/main.go @@ -91,7 +91,6 @@ var runCmd = &cli.Command{ &cli.Float64Flag{Name: "trace-sampler", EnvVars: []string{"VENUS_GATEWAY_TRACE_SAMPLER"}, Value: 1.0}, &cli.StringFlag{Name: "trace-node-name", Value: "venus-gateway"}, &cli.StringFlag{Name: "rate-limit-redis", Hidden: true}, - &cli.BoolFlag{Name: "disable-address-verify", Usage: "disable wallet address veirfication"}, }, Action: func(cctx *cli.Context) error { cfg := config.DefaultConfig() @@ -164,8 +163,6 @@ func parseFlag(cctx *cli.Context, cfg *config.Config) { if cctx.IsSet("rate-limit-redis") { cfg.RateLimit.Redis = cctx.String("rate-limit-redis") } - - cfg.DisableAddressVeirfication = cctx.Bool("disable-address-verify") } func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error { @@ -178,7 +175,7 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error { minerValidator := validator.NewMinerValidator(remoteJwtCli) - walletStream := walletevent.NewWalletEventStream(ctx, remoteJwtCli, requestCfg, cfg.DisableAddressVeirfication) + walletStream := walletevent.NewWalletEventStream(ctx, remoteJwtCli, requestCfg) proofStream := proofevent.NewProofEventStream(ctx, minerValidator, requestCfg) marketStream := marketevent.NewMarketEventStream(ctx, minerValidator, &types.RequestConfig{ diff --git a/walletevent/wallet_event.go b/walletevent/wallet_event.go index 5dc8b64..2385c13 100644 --- a/walletevent/wallet_event.go +++ b/walletevent/wallet_event.go @@ -41,17 +41,14 @@ type WalletEventStream struct { authClient jwtclient.IAuthClient randBytes []byte *types.BaseEventStream - - disableVerifyWalletAddrs bool } -func NewWalletEventStream(ctx context.Context, authClient jwtclient.IAuthClient, cfg *types.RequestConfig, diableVerifyWalletAddrs bool) *WalletEventStream { +func NewWalletEventStream(ctx context.Context, authClient jwtclient.IAuthClient, cfg *types.RequestConfig) *WalletEventStream { walletEventStream := &WalletEventStream{ - walletConnMgr: newWalletConnMgr(), - BaseEventStream: types.NewBaseEventStream(ctx, cfg), - cfg: cfg, - authClient: authClient, - disableVerifyWalletAddrs: diableVerifyWalletAddrs, + walletConnMgr: newWalletConnMgr(), + BaseEventStream: types.NewBaseEventStream(ctx, cfg), + cfg: cfg, + authClient: authClient, } var err error walletEventStream.randBytes, err = ioutil.ReadAll(io.LimitReader(rand.Reader, 32)) @@ -328,11 +325,6 @@ func (w *WalletEventStream) getValidatedAddress(ctx context.Context, channel *ty } func (w *WalletEventStream) verifyAddress(ctx context.Context, addr address.Address, channel *types.ChannelInfo, signBytes []byte, walletAccount string) error { - if w.disableVerifyWalletAddrs { - log.Infof("skip verify account:%s, address: %s, wallet address verification is disabled.", - walletAccount, addr) - return nil - } signData := GetSignData(w.randBytes, signBytes) payload, err := json.Marshal(&sharedGatewayTypes.WalletSignRequest{ Signer: addr, diff --git a/walletevent/wallet_event_test.go b/walletevent/wallet_event_test.go index 1f91341..23c443d 100644 --- a/walletevent/wallet_event_test.go +++ b/walletevent/wallet_event_test.go @@ -142,12 +142,10 @@ func TestAddNewAddress(t *testing.T) { ctx = jwtclient.CtxWithName(ctx, walletAccount) // stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_004 client.wallet.SetFail(ctx, true) - walletEvent.disableVerifyWalletAddrs = false // verify address failed err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) require.Contains(t, err.Error(), "verify address") client.wallet.SetFail(ctx, false) - walletEvent.disableVerifyWalletAddrs = true // stm: @VENUSGATEWAY_WALLET_EVENT_ADD_NEW_ADDRESS_001 err = client.walletEventClient.AddNewAddress(ctx, []address.Address{addr1}) @@ -298,7 +296,7 @@ func setupWalletEvent(t *testing.T, walletAccount string, accounts ...string) *W authClient := mocks.NewMockAuthClient() authClient.AddMockUser(ctx, users...) - return NewWalletEventStream(ctx, authClient, types.DefaultConfig(), true) + return NewWalletEventStream(ctx, authClient, types.DefaultConfig()) } func setupClient(t *testing.T, ctx context.Context, walletAccount string, supportAccounts []string, event *WalletEventStream) *mockClient { From bc3f892a4c55b2e27227ac9ca077791f716df6fc Mon Sep 17 00:00:00 2001 From: simlecode <69969590+simlecode@users.noreply.github.com> Date: Thu, 13 Apr 2023 15:01:45 +0800 Subject: [PATCH 2/2] fix: fix test --- testhelper/memwallet.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testhelper/memwallet.go b/testhelper/memwallet.go index 7b96435..6449b38 100644 --- a/testhelper/memwallet.go +++ b/testhelper/memwallet.go @@ -111,5 +111,6 @@ func (m *MemWallet) WalletSign(ctx context.Context, signer address.Address, toSi if !ok { return nil, fmt.Errorf("address %s not found", signer) } - return vcrypto.Sign(toSign, keyInfo.Key(), vcrypto.SigTypeSecp256k1) + + return vcrypto.Sign(toSign, keyInfo.Key(), sharedTypes.AddressProtocol2SignType(signer.Protocol())) }