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.
This commit is contained in:
Tak Wai Wong 2023-01-19 13:11:35 -08:00 committed by GitHub
parent 425b28f2cc
commit 1c61837bfd
3 changed files with 5 additions and 39 deletions

View file

@ -26,7 +26,6 @@ type EthereumAuthConfig struct {
NetworkUrl string `yaml:"network_url"` // Blockchain network provider URL NetworkUrl string `yaml:"network_url"` // Blockchain network provider URL
ConfigChainID string `yaml:"chain_id"` // Blockchain chain ID. Env variable can replace this property. 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. 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 chainID int
enableAuthz bool // todo: remove this flag when feature is done. enableAuthz bool // todo: remove this flag when feature is done.
} }

View file

@ -30,7 +30,6 @@ var (
version = flag.Bool("version", false, "Shows the current version and exits immediately.") 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.") 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).") 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. // 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) cfg.ClientAPI.PublicKeyAuthentication.Ethereum.ConfigEnableAuthz = strconv.FormatBool(*enableAuthorizationChecks)
logrus.Info("--enable-authz flag is set to ", *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 return cfg
} }

View file

@ -3,7 +3,6 @@ package zion
import ( import (
_ "embed" _ "embed"
"errors" "errors"
"fmt"
"github.com/matrix-org/dendrite/authorization" "github.com/matrix-org/dendrite/authorization"
roomserver "github.com/matrix-org/dendrite/roomserver/api" roomserver "github.com/matrix-org/dendrite/roomserver/api"
@ -12,13 +11,6 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
type ContractVersion uint8
const (
v1 ContractVersion = 1
v2 ContractVersion = 2
)
var ErrSpaceDisabled = errors.New("space disabled") var ErrSpaceDisabled = errors.New("space disabled")
var ErrChannelDisabled = errors.New("channel disabled") var ErrChannelDisabled = errors.New("channel disabled")
@ -26,11 +18,6 @@ func NewZionAuthorization(cfg *config.ClientAPI, roomQueryAPI roomserver.QueryEv
// create the authorization states // create the authorization states
store := NewStore(roomQueryAPI) store := NewStore(roomQueryAPI)
chainId := cfg.PublicKeyAuthentication.Ethereum.GetChainID() chainId := cfg.PublicKeyAuthentication.Ethereum.GetChainID()
contractVersion := v1 // default
if cfg.PublicKeyAuthentication.Ethereum.ContractVersion == "v2" {
contractVersion = v2
}
// initialise the eth client. // initialise the eth client.
if cfg.PublicKeyAuthentication.Ethereum.NetworkUrl == "" { if cfg.PublicKeyAuthentication.Ethereum.NetworkUrl == "" {
log.Errorf("No blockchain network url specified in config\n") 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) log.Errorf("Cannot connect to eth client %v\n", cfg.PublicKeyAuthentication.Ethereum.NetworkUrl)
return nil, err return nil, err
} }
switch contractVersion {
case v1:
return NewZionAuthorizationV1(
chainId,
ethClient,
store,
)
case v2:
return NewZionAuthorizationV2( return NewZionAuthorizationV2(
chainId, chainId,
ethClient, ethClient,
store, store,
) )
default:
errMsg := fmt.Sprintf("Unsupported contract version: %d", contractVersion)
return nil, errors.New(errMsg)
}
} }