Official Go implementation of the Bytom protocol
Révision | 90d7fd990567117a84d14572dbeefa5f44f0d9c0 (tree) |
---|---|
l'heure | 2021-08-24 15:44:55 |
Auteur | shenao78 <shenao.78@163....> |
Commiter | shenao78 |
dynamic_vote_pending_num
@@ -3,6 +3,7 @@ package consensus | ||
3 | 3 | import ( |
4 | 4 | "encoding/binary" |
5 | 5 | "fmt" |
6 | + "math" | |
6 | 7 | "strings" |
7 | 8 | |
8 | 9 | log "github.com/sirupsen/logrus" |
@@ -37,6 +38,7 @@ const ( | ||
37 | 38 | BCRPRequiredBTMAmount = uint64(100000000) |
38 | 39 | |
39 | 40 | BTMAlias = "BTM" |
41 | + defaultVotePendingNum = 302400 | |
40 | 42 | ) |
41 | 43 | |
42 | 44 | type CasperConfig struct { |
@@ -53,11 +55,17 @@ type CasperConfig struct { | ||
53 | 55 | MinValidatorVoteNum uint64 |
54 | 56 | |
55 | 57 | // VotePendingBlockNumber is the locked block number of vote utxo |
56 | - VotePendingBlockNumber uint64 | |
58 | + VotePendingBlockNums []VotePendingBlockNum | |
57 | 59 | |
58 | 60 | FederationXpubs []chainkd.XPub |
59 | 61 | } |
60 | 62 | |
63 | +type VotePendingBlockNum struct { | |
64 | + BeginBlock uint64 | |
65 | + EndBlock uint64 | |
66 | + Num uint64 | |
67 | +} | |
68 | + | |
61 | 69 | // BTMAssetID is BTM's asset id, the soul asset of Bytom |
62 | 70 | var BTMAssetID = &bc.AssetID{ |
63 | 71 | V0: binary.BigEndian.Uint64([]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}), |
@@ -119,7 +127,10 @@ var MainNetParams = Params{ | ||
119 | 127 | MaxTimeOffsetMs: 3000, |
120 | 128 | BlocksOfEpoch: 100, |
121 | 129 | MinValidatorVoteNum: 1e14, |
122 | - VotePendingBlockNumber: 14400, | |
130 | + VotePendingBlockNums: []VotePendingBlockNum{ | |
131 | + {BeginBlock: 0, EndBlock: 432000, Num: 14400}, | |
132 | + {BeginBlock: 432000, EndBlock: math.MaxUint64, Num: defaultVotePendingNum}, | |
133 | + }, | |
123 | 134 | FederationXpubs: []chainkd.XPub{ |
124 | 135 | xpub("f9003633ccbd8cc37e034f4dbe70d9fae980d437948d8cb908d0cab7909780d74a324b4decb5dfcd43fbc6b896ac066b7e02c733a1537360e933278a101a850c"), |
125 | 136 | xpub("d301fee5d4ba7eb5b9d41ca13ec56c19daceb5f6b752d91d49777fd1fc7c45891e5773cafb3b6d6ab764ef2794e8ba953c8bdb9dc77a3af51e979f96885f96b2"), |
@@ -140,7 +151,7 @@ var TestNetParams = Params{ | ||
140 | 151 | MaxTimeOffsetMs: 3000, |
141 | 152 | BlocksOfEpoch: 100, |
142 | 153 | MinValidatorVoteNum: 1e8, |
143 | - VotePendingBlockNumber: 10, | |
154 | + VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}}, | |
144 | 155 | FederationXpubs: []chainkd.XPub{ |
145 | 156 | xpub("7732fac62320799ff5e4eec1dc4ba7b07dc0e5a647850bf0bc34cb9aca195a05a1118b57d377947d7936156c831c87b700ed945a82cae63aff14905beb39d001"), |
146 | 157 | xpub("08543fef8c3ca27483954f80eee6d461c307b6aa564aafaf235a4bd2740debbc71b14af78715c94cbc1d16fa84da97a3eabc5b21f003ab49882e4af7f9f00bbd"), |
@@ -159,11 +170,20 @@ var SoloNetParams = Params{ | ||
159 | 170 | MaxTimeOffsetMs: 24000, |
160 | 171 | BlocksOfEpoch: 100, |
161 | 172 | MinValidatorVoteNum: 1e8, |
162 | - VotePendingBlockNumber: 10, | |
173 | + VotePendingBlockNums: []VotePendingBlockNum{{BeginBlock: 0, EndBlock: math.MaxUint64, Num: 10}}, | |
163 | 174 | FederationXpubs: []chainkd.XPub{}, |
164 | 175 | }, |
165 | 176 | } |
166 | 177 | |
178 | +func VotePendingBlockNums(height uint64) uint64 { | |
179 | + for _, pendingNum := range ActiveNetParams.VotePendingBlockNums { | |
180 | + if height >= pendingNum.BeginBlock && height < pendingNum.EndBlock { | |
181 | + return pendingNum.Num | |
182 | + } | |
183 | + } | |
184 | + return defaultVotePendingNum | |
185 | +} | |
186 | + | |
167 | 187 | // InitActiveNetParams load the config by chain ID |
168 | 188 | func InitActiveNetParams(chainID string) error { |
169 | 189 | var exist bool |
@@ -42,7 +42,7 @@ func (view *UtxoViewpoint) applySpendUtxo(block *bc.Block, tx *bc.Tx) error { | ||
42 | 42 | return errors.New("coinbase utxo is not ready for use") |
43 | 43 | } |
44 | 44 | case storage.VoteUTXOType: |
45 | - if entry.BlockHeight + consensus.ActiveNetParams.VotePendingBlockNumber > block.Height { | |
45 | + if entry.BlockHeight + consensus.VotePendingBlockNums(block.Height) > block.Height { | |
46 | 46 | return errors.New("Coin is within the voting lock time") |
47 | 47 | } |
48 | 48 | } |
@@ -230,7 +230,7 @@ func txOutToUtxos(tx *types.Tx, blockHeight uint64) []*account.UTXO { | ||
230 | 230 | } |
231 | 231 | |
232 | 232 | case *bc.VoteOutput: |
233 | - voteValidHeight := blockHeight + consensus.ActiveNetParams.VotePendingBlockNumber | |
233 | + voteValidHeight := blockHeight + consensus.VotePendingBlockNums(blockHeight) | |
234 | 234 | if validHeight < voteValidHeight { |
235 | 235 | validHeight = voteValidHeight |
236 | 236 | } |