Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vspclosedmsg config. #269

Merged
merged 1 commit into from Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions config.go
Expand Up @@ -62,6 +62,7 @@ type config struct {
SupportEmail string `long:"supportemail" ini-name:"supportemail" description:"Email address for users in need of support."`
BackupInterval time.Duration `long:"backupinterval" ini-name:"backupinterval" description:"Time period between automatic database backups. Valid time units are {s,m,h}. Minimum 30 seconds."`
VspClosed bool `long:"vspclosed" ini-name:"vspclosed" description:"Closed prevents the VSP from accepting new tickets."`
VspClosedMsg string `long:"vspclosedmsg" ini-name:"vspclosedmsg" description:"A short message displayed on the webpage and returned by the status API endpoint if vspdclosed is true."`
AdminPass string `long:"adminpass" ini-name:"adminpass" description:"Password for accessing admin page."`
Designation string `long:"designation" ini-name:"designation" description:"Short name for the VSP. Customizes the logo in the top toolbar."`

Expand Down Expand Up @@ -292,6 +293,11 @@ func loadConfig() (*config, error) {
return nil, errors.New("invalid vspfee - should be greater than 0.01 and less than 100.0")
}

// If VSP is not closed, ignore any provided closure message.
if !cfg.VspClosed {
cfg.VspClosedMsg = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why this needs to be set to nil if there is a flag available which can be checked before the message is used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This same if statement will still need to exist in vspinfo.go to ensure that the message is only included in /vspinfo response when the VSP is actually closed.

I put it in config.go instead because the value of VspClosedMsg should never be used when VspClosed == true, so putting it here will prevent the need for it to be duplicated in other places which might access the closed message in future.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that, but ignoring the closure message by setting it to an empty string isn't intuitive to me, if the checking the flag precedes using the closure message then it'd only be displayed if the check passes anyway so why mutate the config value? Plus the check isn't expensive. The current approach works and I do not have a strong opinion on this, take another look however.

}

// Ensure the support email address is set.
if cfg.SupportEmail == "" {
return nil, errors.New("the supportemail option is not set")
Expand Down Expand Up @@ -409,7 +415,7 @@ func loadConfig() (*config, error) {
// If database already exists, return error.
if fileExists(cfg.dbPath) {
return nil, fmt.Errorf("database already initialized at %s, "+
"--feexpub option is not needed.", cfg.dbPath)
"--feexpub option is not needed", cfg.dbPath)
}

// Ensure provided value is a valid key for the selected network.
Expand All @@ -431,7 +437,7 @@ func loadConfig() (*config, error) {
// If database does not exist, return error.
if !fileExists(cfg.dbPath) {
return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+
" --feexpub option to initialize one.", dataDir)
" --feexpub option to initialize one", dataDir)
}
}

Expand Down
1 change: 1 addition & 0 deletions docs/api.md
Expand Up @@ -49,6 +49,7 @@ when a VSP is closed will result in an error.
"pubkey":"SjAmrAqH7LScCUwM1qo5O6Cu7aKhrM1ORszgZwD7HmU=",
"feepercentage":3.0,
"vspclosed":false,
"vspclosedmsg": "",
"network":"testnet3",
"vspdversion":"1.0.0-pre",
"voting":10,
Expand Down
1 change: 1 addition & 0 deletions harness.sh
Expand Up @@ -151,6 +151,7 @@ webserverdebug = false
supportemail = example@test.com
backupinterval = 3m0s
vspclosed = false
vspclosedmsg = Your tickets are no longer welcome here. Please go away.
adminpass=12345
designation = harness
EOF
Expand Down
1 change: 1 addition & 0 deletions vspd.go
Expand Up @@ -90,6 +90,7 @@ func run(ctx context.Context) error {
BlockExplorerURL: cfg.netParams.BlockExplorerURL,
SupportEmail: cfg.SupportEmail,
VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
AdminPass: cfg.AdminPass,
Debug: cfg.WebServerDebug,
Designation: cfg.Designation,
Expand Down
2 changes: 2 additions & 0 deletions webapi/homepage.go
Expand Up @@ -30,6 +30,7 @@ type vspStats struct {
UpdateTime string
SupportEmail string
VspClosed bool
VspClosedMsg string
Debug bool
Designation string
BlockHeight uint32
Expand Down Expand Up @@ -60,6 +61,7 @@ func initVSPStats() {
Network: cfg.NetParams.Name,
SupportEmail: cfg.SupportEmail,
VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
Debug: cfg.Debug,
Designation: cfg.Designation,
}
Expand Down
13 changes: 10 additions & 3 deletions webapi/templates/homepage.html
Expand Up @@ -5,9 +5,16 @@

{{ if .VspStats.VspClosed }}
<div class="alert alert-danger">
<h4 class="alert-heading">This Voting Service Provider is closed</h4>
A closed VSP will still vote on tickets with already paid fees, but will not accept new any tickets.
Visit <a href="https://decred.org/vsp/" class="alert-link" target="_blank" rel="noopener noreferrer">decred.org</a> to find a new VSP.
<h4 class="alert-heading mb-3">
This Voting Service Provider is closed
</h4>
<p>
{{ .VspStats.VspClosedMsg }}
jholdstock marked this conversation as resolved.
Show resolved Hide resolved
</p>
<p>
A closed VSP will still vote on tickets with already paid fees, but will not accept new any tickets.
Visit <a href="https://decred.org/vsp/" class="alert-link" target="_blank" rel="noopener noreferrer">decred.org</a> to find a new VSP.
</p>
</div>
{{ end }}

Expand Down
1 change: 1 addition & 0 deletions webapi/types.go
Expand Up @@ -10,6 +10,7 @@ type vspInfoResponse struct {
PubKey []byte `json:"pubkey"`
FeePercentage float64 `json:"feepercentage"`
VspClosed bool `json:"vspclosed"`
VspClosedMsg string `json:"vspclosedmsg"`
Network string `json:"network"`
VspdVersion string `json:"vspdversion"`
Voting int64 `json:"voting"`
Expand Down
1 change: 1 addition & 0 deletions webapi/vspinfo.go
Expand Up @@ -21,6 +21,7 @@ func vspInfo(c *gin.Context) {
FeePercentage: cfg.VSPFee,
Network: cfg.NetParams.Name,
VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
VspdVersion: version.String(),
Voting: cachedStats.Voting,
Voted: cachedStats.Voted,
Expand Down
1 change: 1 addition & 0 deletions webapi/webapi.go
Expand Up @@ -31,6 +31,7 @@ type Config struct {
FeeAccountName string
SupportEmail string
VspClosed bool
VspClosedMsg string
AdminPass string
Debug bool
Designation string
Expand Down