-
Notifications
You must be signed in to change notification settings - Fork 153
/
deployments.go
118 lines (106 loc) · 3.69 KB
/
deployments.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Copyright (c) 2018 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package deployments
import (
"context"
"decred.org/dcrwallet/v2/errors"
"decred.org/dcrwallet/v2/rpc/client/dcrd"
"github.com/decred/dcrd/chaincfg/v3"
dcrdtypes "github.com/decred/dcrd/rpc/jsonrpc/types/v3"
"github.com/decred/dcrd/wire"
)
// HardcodedDeployment specifies hardcoded block heights that a deployment
// activates at. If the value is negative, the deployment is either inactive or
// can't be determined due to the uniqueness properties of the network.
//
// Since these are hardcoded deployments, and cannot support every possible
// network, conditional logic should only be applied when a deployment is
// active, not when it is inactive.
type HardcodedDeployment struct {
MainNetActivationHeight int32
TestNet2ActivationHeight int32
TestNet3ActivationHeight int32
SimNetActivationHeight int32
}
// DCP0001 specifies hard forking changes to the stake difficulty algorithm as
// defined by https://github.com/decred/dcps/blob/master/dcp-0001/dcp-0001.mediawiki.
var DCP0001 = HardcodedDeployment{
MainNetActivationHeight: 149248,
TestNet2ActivationHeight: 46128,
TestNet3ActivationHeight: 0,
SimNetActivationHeight: 0,
}
// DCP0002 specifies the activation of the OP_SHA256 hard fork as defined by
// https://github.com/decred/dcps/blob/master/dcp-0002/dcp-0002.mediawiki.
var DCP0002 = HardcodedDeployment{
MainNetActivationHeight: 189568,
TestNet2ActivationHeight: 151968,
TestNet3ActivationHeight: 0,
SimNetActivationHeight: 0,
}
// DCP0003 specifies the activation of a CSV soft fork as defined by
// https://github.com/decred/dcps/blob/master/dcp-0003/dcp-0003.mediawiki.
var DCP0003 = HardcodedDeployment{
MainNetActivationHeight: 189568,
TestNet2ActivationHeight: 151968,
TestNet3ActivationHeight: 0,
SimNetActivationHeight: 0,
}
// Active returns whether the hardcoded deployment is active at height on the
// network specified by params. Active always returns false for unrecognized
// networks.
func (d *HardcodedDeployment) Active(height int32, net wire.CurrencyNet) bool {
var activationHeight int32 = -1
switch net {
case wire.MainNet:
activationHeight = d.MainNetActivationHeight
case 0x48e7a065: // testnet2
activationHeight = d.TestNet2ActivationHeight
case wire.TestNet3:
activationHeight = d.TestNet3ActivationHeight
case wire.SimNet:
activationHeight = d.SimNetActivationHeight
}
return activationHeight >= 0 && height >= activationHeight
}
const (
lockedinStatus = "lockedin"
activeStatus = "active"
)
// DCP0010Active returns whether the consensus rules for the next block with the
// current chain tip height requires the subsidy split as specified in DCP0010.
// DCP0010 is always active on simnet, and requires the RPC syncer to detect
// activation on mainnet and testnet3.
func DCP0010Active(ctx context.Context, height int32, params *chaincfg.Params,
syncer interface{}) (bool, error) {
net := params.Net
rcai := int32(params.RuleChangeActivationInterval)
if net == wire.SimNet {
return true, nil
}
if net != wire.MainNet && net != wire.TestNet3 {
return false, nil
}
rpc, ok := syncer.(*dcrd.RPC)
if !ok {
return false, errors.E(errors.Bug, "DCP0010 activation check requires RPC syncer")
}
var resp dcrdtypes.GetBlockChainInfoResult
err := rpc.Call(ctx, "getblockchaininfo", &resp)
if err != nil {
return false, err
}
d, ok := resp.Deployments[chaincfg.VoteIDChangeSubsidySplit]
if !ok {
return false, nil
}
switch {
case d.Status == lockedinStatus && height == int32(d.Since)+rcai-1:
return true, nil
case d.Status == activeStatus:
return true, nil
default:
return false, nil
}
}