From 1c61837bfd92f738399997120cb03759568003f3 Mon Sep 17 00:00:00 2001 From: Tak Wai Wong <64229756+tak-hntlabs@users.noreply.github.com> Date: Thu, 19 Jan 2023 13:11:35 -0800 Subject: [PATCH] fix client and dendrite to always use v2 smart contracts (#1259) Remove the logic to switch between v1 and v2 smart contracts. Always use v2. --- setup/config/config_publickey.go | 1 - setup/flags.go | 7 ------- zion/zion_authorization.go | 36 +++++--------------------------- 3 files changed, 5 insertions(+), 39 deletions(-) diff --git a/setup/config/config_publickey.go b/setup/config/config_publickey.go index 42d3acb3b..909f538a0 100644 --- a/setup/config/config_publickey.go +++ b/setup/config/config_publickey.go @@ -26,7 +26,6 @@ type EthereumAuthConfig struct { NetworkUrl string `yaml:"network_url"` // Blockchain network provider URL ConfigChainID string `yaml:"chain_id"` // Blockchain chain ID. Env variable can replace this property. ConfigEnableAuthz string `yaml:"enable_authz"` // Enable / disable authorization during development. todo: remove this flag when feature is done. - ContractVersion string // todo: remove this setting when v2 migration is done. chainID int enableAuthz bool // todo: remove this flag when feature is done. } diff --git a/setup/flags.go b/setup/flags.go index fde7f2d4e..2004d24d0 100644 --- a/setup/flags.go +++ b/setup/flags.go @@ -30,7 +30,6 @@ var ( version = flag.Bool("version", false, "Shows the current version and exits immediately.") enableRegistrationWithoutVerification = flag.Bool("really-enable-open-registration", false, "This allows open registration without secondary verification (reCAPTCHA). This is NOT RECOMMENDED and will SIGNIFICANTLY increase the risk that your server will be used to send spam or conduct attacks, which may result in your server being banned from rooms.") enableAuthorizationChecks = flag.Bool("enable-authz", false, "Enables authorization checks (aka space/channel gating).") - contractVersion = flag.String("contract-version", "v1", "Contract version to use. Valid values are v1 and v2. Default is v1. Remove this flag when v2 migration is done.") ) // ParseFlags parses the commandline flags and uses them to create a config. @@ -61,11 +60,5 @@ func ParseFlags(monolith bool) *config.Dendrite { cfg.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigEnableAuthz = strconv.FormatBool(*enableAuthorizationChecks) logrus.Info("--enable-authz flag is set to ", *enableAuthorizationChecks) - // cmdline --contract-version. Contract version to use. Valid values are v1 - // and v2. Default is v1. - // todo: Remove this flag when v2 migration is done. - cfg.ClientAPI.PublicKeyAuthentication.Ethereum.ContractVersion = *contractVersion - logrus.Info("--contract-version flag is set to ", *contractVersion) - return cfg } diff --git a/zion/zion_authorization.go b/zion/zion_authorization.go index 41178aadc..5db68dffc 100644 --- a/zion/zion_authorization.go +++ b/zion/zion_authorization.go @@ -3,7 +3,6 @@ package zion import ( _ "embed" "errors" - "fmt" "github.com/matrix-org/dendrite/authorization" roomserver "github.com/matrix-org/dendrite/roomserver/api" @@ -12,13 +11,6 @@ import ( log "github.com/sirupsen/logrus" ) -type ContractVersion uint8 - -const ( - v1 ContractVersion = 1 - v2 ContractVersion = 2 -) - var ErrSpaceDisabled = errors.New("space disabled") var ErrChannelDisabled = errors.New("channel disabled") @@ -26,11 +18,6 @@ func NewZionAuthorization(cfg *config.ClientAPI, roomQueryAPI roomserver.QueryEv // create the authorization states store := NewStore(roomQueryAPI) chainId := cfg.PublicKeyAuthentication.Ethereum.GetChainID() - contractVersion := v1 // default - if cfg.PublicKeyAuthentication.Ethereum.ContractVersion == "v2" { - contractVersion = v2 - } - // initialise the eth client. if cfg.PublicKeyAuthentication.Ethereum.NetworkUrl == "" { log.Errorf("No blockchain network url specified in config\n") @@ -41,22 +28,9 @@ func NewZionAuthorization(cfg *config.ClientAPI, roomQueryAPI roomserver.QueryEv log.Errorf("Cannot connect to eth client %v\n", cfg.PublicKeyAuthentication.Ethereum.NetworkUrl) return nil, err } - - switch contractVersion { - case v1: - return NewZionAuthorizationV1( - chainId, - ethClient, - store, - ) - case v2: - return NewZionAuthorizationV2( - chainId, - ethClient, - store, - ) - default: - errMsg := fmt.Sprintf("Unsupported contract version: %d", contractVersion) - return nil, errors.New(errMsg) - } + return NewZionAuthorizationV2( + chainId, + ethClient, + store, + ) }