Use DCP-0010 status to calculate fees.
vspd will now call dcrd RPC `getblockchaininfo` to determine if DCP-0010 is active, and take that information into consideration when calculating ticket registration fee.
This commit is contained in:
parent
74aa7bcd13
commit
040ed56f11
@ -3,6 +3,7 @@
|
||||
[](https://github.com/decred/vspd/actions)
|
||||
[](http://copyfree.org)
|
||||
[](https://goreportcard.com/report/github.com/decred/vspd)
|
||||
[](https://github.com/decred/vspd/releases/latest)
|
||||
|
||||
## Overview
|
||||
|
||||
|
||||
@ -63,6 +63,11 @@ func (n *NotificationHandler) Notify(method string, params json.RawMessage) erro
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NotificationHandler) Close() error {
|
||||
close(notifierClosed)
|
||||
return nil
|
||||
}
|
||||
|
||||
// blockConnected is called once when vspd starts up, and once each time a
|
||||
// blockconnected notification is received from dcrd.
|
||||
func blockConnected() {
|
||||
@ -306,11 +311,6 @@ func blockConnected() {
|
||||
|
||||
}
|
||||
|
||||
func (n *NotificationHandler) Close() error {
|
||||
close(notifierClosed)
|
||||
return nil
|
||||
}
|
||||
|
||||
func connectNotifier(shutdownCtx context.Context, dcrdWithNotifs rpc.DcrdConnect) error {
|
||||
notifierClosed = make(chan struct{})
|
||||
|
||||
|
||||
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/decred/vspd
|
||||
go 1.16
|
||||
|
||||
require (
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc1
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc3
|
||||
github.com/decred/dcrd/blockchain/stake/v4 v4.0.0
|
||||
github.com/decred/dcrd/blockchain/v4 v4.0.0
|
||||
github.com/decred/dcrd/chaincfg/chainhash v1.0.3
|
||||
|
||||
6
go.sum
6
go.sum
@ -1,7 +1,7 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
decred.org/cspp/v2 v2.0.0-20211207170141-a6b5f958a91f/go.mod h1:USyJS44Kqxz2wT/VaNsf9iTAONegO/qKXRdLg1nvrWI=
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc1 h1:lJuI3srFWmy5SNB5X4e2X9xJZXXJ6hMbI3bsXEqBfPQ=
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc1/go.mod h1:IOIVwOFCpA1Xhqz4Xo26IaD5qZN01EZRGyCJOZYnoc4=
|
||||
decred.org/cspp/v2 v2.0.0-20220117153402-4f26c92d52a3/go.mod h1:USyJS44Kqxz2wT/VaNsf9iTAONegO/qKXRdLg1nvrWI=
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc3 h1:xxmZndkTheyfORD16nf8fUsevR3dBHdI8hhdAUFumZE=
|
||||
decred.org/dcrwallet/v2 v2.0.0-rc3/go.mod h1:NJnnnOrPISrCt5oxrkXgTu0feCnxcLUsbqsvdXtFVBI=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
|
||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
||||
|
||||
21
rpc/dcrd.go
21
rpc/dcrd.go
@ -12,6 +12,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/decred/dcrd/blockchain/v4"
|
||||
"github.com/decred/dcrd/chaincfg/v3"
|
||||
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
|
||||
"github.com/decred/dcrd/wire"
|
||||
@ -21,6 +22,8 @@ import (
|
||||
|
||||
var (
|
||||
requiredDcrdVersion = semver{Major: 7, Minor: 0, Patch: 0}
|
||||
|
||||
activeStatus = blockchain.ThresholdStateTuple{State: blockchain.ThresholdActive}.String()
|
||||
)
|
||||
|
||||
// These error codes are defined in dcrd/dcrjson. They are copied here so we
|
||||
@ -140,6 +143,24 @@ func (c *DcrdRPC) SendRawTransaction(txHex string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsDCP0010Active uses getblockchaininfo RPC to determine if the DCP-0010
|
||||
// agenda has activated on the current network.
|
||||
func (c *DcrdRPC) IsDCP0010Active() (bool, error) {
|
||||
var info dcrdtypes.GetBlockChainInfoResult
|
||||
err := c.Call(c.ctx, "getblockchaininfo", &info)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
agenda, ok := info.Deployments[chaincfg.VoteIDChangeSubsidySplit]
|
||||
if !ok {
|
||||
return false, fmt.Errorf("getblockchaininfo did not return agenda %q",
|
||||
chaincfg.VoteIDChangeSubsidySplit)
|
||||
}
|
||||
|
||||
return agenda.Status == activeStatus, nil
|
||||
}
|
||||
|
||||
// NotifyBlocks uses notifyblocks RPC to request new block notifications from dcrd.
|
||||
func (c *DcrdRPC) NotifyBlocks() error {
|
||||
return c.Call(c.ctx, "notifyblocks", nil)
|
||||
|
||||
@ -40,11 +40,14 @@ func getNewFeeAddress(db *database.VspDatabase, addrGen *addressGenerator) (stri
|
||||
return addr, idx, nil
|
||||
}
|
||||
|
||||
// getCurrentFee returns the minimum fee amount a client should pay in order to
|
||||
// register a ticket with the VSP at the current block height.
|
||||
func getCurrentFee(dcrdClient *rpc.DcrdRPC) (dcrutil.Amount, error) {
|
||||
bestBlock, err := dcrdClient.GetBestBlockHeader()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
sDiff, err := dcrutil.NewAmount(bestBlock.SBits)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
@ -53,13 +56,15 @@ func getCurrentFee(dcrdClient *rpc.DcrdRPC) (dcrutil.Amount, error) {
|
||||
// Using a hard-coded amount for relay fee is acceptable here because this
|
||||
// amount is never actually used to construct or broadcast transactions. It
|
||||
// is only used to calculate the fee charged for adding a ticket to the VSP.
|
||||
relayFee, err := dcrutil.NewAmount(0.0001)
|
||||
const defaultMinRelayTxFee = dcrutil.Amount(1e4)
|
||||
|
||||
isDCP0010Active, err := dcrdClient.IsDCP0010Active()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
fee := txrules.StakePoolTicketFee(sDiff, relayFee, int32(bestBlock.Height),
|
||||
cfg.VSPFee, cfg.NetParams)
|
||||
fee := txrules.StakePoolTicketFee(sDiff, defaultMinRelayTxFee,
|
||||
int32(bestBlock.Height), cfg.VSPFee, cfg.NetParams, isDCP0010Active)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user